An Ansible® Playbook is a blueprint of automation tasks, which are IT actions executed with limited manual effort across an inventory of IT solutions. Playbooks tell Ansible what to do to which devices.
Instead of manually applying the same action to hundreds or thousands of similar technologies across IT environments, executing a playbook automatically completes the same action for the specified type of inventory—such as a set of routers. Playbooks also serve as frameworks of prewritten code that developers can use ad-hoc or as a starting template.
Playbooks are regularly used to automate IT infrastructure—such as operating systems and Kubernetes platforms—networks, security systems, and code repositories like GitHub. IT staff can use playbooks to program applications, services, server nodes, and other devices, without the manual overhead of creating everything from scratch.
And playbooks—as well as the conditions, variables, and tasks within them—can be saved, shared, or reused indefinitely. This makes it easier for IT teams to codify operational knowledge and ensure that the same actions are performed consistently.
Ansible Playbooks are lists of tasks that automatically execute for your specified inventory or groups of hosts. One or more Ansible tasks can be combined to make a play—an ordered grouping of tasks mapped to specific hosts—and tasks are executed in the order in which they are written. A playbook can include one or more play.
Tasks are executed by modules, each of which performs a specific task in a playbook. A module contains metadata that determines when and where a task is executed, as well as which user executes it. There are thousands of Ansible modules that perform all kinds of IT tasks, such as:
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 become: true tasks: - name: Ensure apache is at the latest version ansible.builtin.yum: name: httpd state: latest - name: Write the apache config file ansible.builtin.template: src: /srv/httpd.j2 dest: /etc/httpd.conf mode: "0644" - name: Update db servers hosts: databases become: true tasks: - name: Ensure postgresql is at the latest version ansible.builtin.yum: name: postgresql state: latest - name: Ensure that postgresql is started ansible.builtin.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.
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.
Because YAML is a human-readable language, IT professionals with specific domain expertise—like in network, security, or cloud—can create playbooks without having to learn a complicated coding language.
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.
Red Hat Ansible Automation Platform is a unified platform that can automate full processes across your IT domains for a variety of use cases—including infrastructure, hybrid cloud, security, and networks, all the way to edge locations. Ansible Automation Platform includes all the tools needed to implement enterprise-wide automation, including an event-driven solution, playbooks, and analytics. And it allows your teams to centralize and control your IT infrastructure with a visual dashboard, role-based access control, and other features that will help reduce operational complexity.
With a Red Hat subscription, you get certified, supported content from Red Hat and our partners, 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.
The introduction of Ansible Lightspeed with IBM Watson Code Assistant makes Ansible even more accessible to beginners and helps experienced Ansible creators be more productive, efficient, and error-free. Developers can enter a task request in plain English, and Ansible Lightspeed interacts with IBM watsonx foundation models to generate code recommendations that are then used to create playbooks.
How much time could automation save you?
Answer a few short questions to find out how much time you could save by using Ansible Automation Platform across your organization.