Overview
An Ansible® Playbook is a blueprint of automation tasks—which are complex IT actions executed with limited or no human involvement. Ansible Playbooks are executed on a set, group, or classification of hosts, which together make up an Ansible inventory.
Ansible Playbooks are essentially frameworks, which are prewritten code developers can use ad-hoc or as starting template. Ansible Playbooks are regularly used to automate IT infrastructure (such as operating systems and Kubernetes platforms), networks, security systems, and developer personas (such as Git).
Ansible Playbooks help IT staff program applications, services, server nodes, or other devices without the manual overhead of creating everything from scratch. And Ansible Playbooks—as well as the conditions, variables, and tasks within them—can be saved, shared, or reused indefinitely.
How do Ansible Playbooks work?
Ansible modules execute tasks. One or more Ansible tasks can be combined to make a play. Two or more plays can be combined to create an Ansible Playbook. Ansible Playbooks are lists of tasks that automatically execute against hosts. Groups of hosts form your Ansible inventory.
Each module within an Ansible Playbook performs a specific task. Each module contains metadata that determines when and where a task is executed, as well as which user executes it. There are thousands of other Ansible modules that perform all kinds of IT tasks, such as:
Cloud management
oci_vcn creates, deletes, or updates virtual cloud networks in Oracle Cloud Infrastructure environments. Similarly, vmware_cluster adds, removes, or updates VMware vSphere clusters.
User management
selogin maps Linux® operating system (OS) users to SELinux user, and gitlab_user creates, updates, or deletes GitLab users.
Networking
Dozens of modules handle application programming interfaces (APIs); Cisco IOS, NXOS, and IOS XR devices; as well as F5 BIG-IP services.
Security
Openssh_cert generates an OpenSSH host or user certificates, and ipa_config manages global FreeIPA configuration settings.
Communication
mail can automatically send emails based on certain criteria, and snow_record creates, deletes, or updates a single record in ServiceNow.
Watch sessions from AnsibleFest 2022
AnsibleFest 2022 may be over, but you can keep building your automation knowledge. Explore our on-demand content hub, with more than 50 AnsibleFest sessions on automation use cases, processes, and more. Sign up for free to view all content until April 2023.
A practical example of an Ansible Playbook
Ansible is capable of communicating with many different device classifications, from cloud-based REST APIs, to Linux and Windows systems, networking hardware, and much more. This is a sample of 2 Ansible modules automatically updating 2 types of servers:
--- name: update web servers hosts: webservers remote_user: root tasks: - name: ensure apache is at the latest version yum: name: httpd state: latest - name: write the apache config file template: src: /srv/httpd.j2 dest: /etc/httpd.conf - name: update db servers hosts: databases remote_user: root tasks: - name: ensure postgresql is at the latest version yum: name: postgresql state: latest - name: ensure that postgresql is started service: name: postgresql state: started
The playbook contains 2 plays:
- The first checks whether or not web server software is up to date and runs the update if necessary
- The second checks whether or not database server software is up to date and runs the update if necessary
How do I use Ansible Playbooks?
Ansible uses the YAML syntax. Depending on whom you ask, YAML stands for yet another markup language or YAML ain’t markup language (a recursive acronym). There are also 2 different, but perfectly acceptable, YAML file extensions: .yaml or .yml.
There are 2 ways of using Ansible Playbooks: From the command line interface (CLI) or using the Red Hat Ansible Automation Platform’s push-button deployments.
From the CLI
After installing the open source Ansible project or Red Hat Ansible Automation Platform (which is as straightforward as typing sudo yum install ansible in the Red Hat Enterprise Linux CLI), all you need to do is use the ansible-playbook command to run Ansible Playbooks.
From within the platform
The Red Hat Ansible Automation Platform web-based user interface includes push-button Ansible Playbook deployments that are used as part of larger jobs (or job templates). These deployments come with additional safeguards that are particularly helpful to users who are newer to IT automation—or those without as much experience working in the CLI.
There’s a lot more to do with automation.
Why Red Hat?
Red Hat® Ansible Automation Platform uses human-readable YAML language so users can share, vet, and manage automation content. It includes all the tools needed to implement enterprise-wide automation, including playbooks and analytics. And it allows your teams to centralize and control your IT infrastructure with a visual dashboard, role-based access control, and more to reduce operational complexity.
With a Red Hat subscription, you get certified content from our robust partner ecosystem, access to hosted management services, and life cycle technical support to scale automation across your organization. And you’ll get expert knowledge gained from our success with thousands of customers.