Ansible playbook best practices
It is important to develop your Ansible playbooks with reader-friendliness and reusability in mind. Since the YAML format is human readable, it is easy to develop and follow some style guides for your Ansible playbooks.
In Chapter 15, Using Raw Commands for Network Operations, you learned when to use the raw
module and commands. Always check the documentation and see if there are modules available for your task. The command
, shell
, raw
, and script
modules can be used if no suitable modules are available for the task. But always keep in mind that the command
, shell
, raw
, and script
modules are not idempotent and will always report as changed
when executed.
Always give your tasks names
Even though the name
parameter is an optional component, it is a best practice to provide an appropriate and meaningful name for the plays, tasks, blocks, and other components in your Ansible playbooks. Refer to Figure 16.22, where you can see the sample names that...