Grafvision - Fotolia
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 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 Configuration Management and DevOps
Related Q&A from Stuart Burns
Even though Ansible has its roots in open source software and Linux, is it possible to use the configuration management tool for Windows environments? Continue Reading
Roles are one of several functions in Ansible that simplify and streamline IT automation processes. Dig into this quick overview to learn the basics ... Continue Reading
VMware's ESXi hypervisor is free to license and use, but its capabilities are limited without vSphere. You get what you pay for. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.