Grafvision - Fotolia

How do I get started with an Ansible playbook?

An Ansible playbook boosts admin productivity when they manage configurations across machines. Learn how playbooks work and how to avoid live errors.

Rather than run individual Ansible commands one by one, admins streamline their use of the configuration management tool through a playbook.

An Ansible playbook is a self-contained and organized collection of automation scripts, called plays, that define the configuration management work Ansible is set to perform on one or multiple machines. Playbooks are not standard text files, but are formatted with YAML. Once you're familiar with Ansible commands, write playbooks from scratch, or pull in pre-written roles and modules from Ansible and its user community.

To start working with these Ansible playbooks, verify that the tool is installed and operating.  Issue the following command to run a playbook, where myfile is the YAML file name:

ansible-playbook myfile.yml

Ansible communicates with the machines it manages via SSH, so the Ansible playbook and the executable Ansible files are stored within folders on the local server.

Use check mode and groups

It's a good idea to run playbooks in "check mode" before they execute on real systems, especially for those admins new to using Ansible. This action will run the playbook without modifying any files, and then output the changes that would have been made if the system had run in standard mode.

To use check mode, add --check as a runtime flag, for example:

ansible-playbook myfile.yml --check

To check for broken syntax, use the command:

ansible-playbook myfile.yml --syntax-check

Admins can group together similar host machines, in terms of their function or another hierarchy, and execute plays only against those hosts in a group. This separation can be helpful, as an example, to ensure only the web servers -- not the database servers -- run the latest version of Apache.

All hosts are stored in a local Ansible inventory file called /etc/ansible/hosts. While admins can change where host information is stored, this location is the default setting and a best practice. If this file changes frequently, use version control to manage it; this makes it easier to see which hosts have been added or removed.

When you work with Ansible playbooks, make the strategy fit with Ansible's purpose to implement a consistent desired configuration -- the desired state -- for each host machine.

Dig Deeper on Systems automation and orchestration

Software Quality
App Architecture
Cloud Computing
SearchAWS
TheServerSide.com
Data Center
Close