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 Systems automation and orchestration
Related Q&A from Stuart Burns
Backup strategy and frequency is unique for just about every organization. You must balance backup management abilities with the amount of loss your ... Continue Reading
Git reset and git revert can be lifesavers for developers. Follow these examples to see which command makes the most sense when mistakes arise during... Continue Reading
When backing up SAP HANA databases, having the right tools for the organization is critical. Data snapshots are one option, but not the only one ... Continue Reading