Ansible Gotchas, Tricks, and Tools [Part 2]
Playbooks and roles
In the previous post, I showed the basic structure to start off with. In this post, I hope to go over some basics as what are in those files.
What is a Playbook?
Playbooks can declare configurations, but they can also orchestrate steps of any manually ordered process, even as different steps must bounce back and forth between sets of machines in particular orders. They can launch tasks synchronously or asynchronously.
The playbook in the previous post was placed in the folder structure under playbook
directory. These files are written in Ansible's preferred way to write configuration management scripts YAML. IMHO the best way to write management scripts.
What is a Role?
Roles are ways of automatically loading certain vars_files, tasks, and handlers based on a known file structure. Grouping content by roles also allows easy sharing of roles with other users.
Difference between roles and playbooks
I really like to use the LEGO plan analogy when explaining what a playbook is what a role is and how they interact with each other.
Please check the lego plan below;
Please notice how this LEGO plan can be separated into two parts. One part of putting together the humanoid the second part is putting together the ambulance. Now the thing is that for any LEGO project you might have you might use these plans separately.
That is the essence of the difference in what you should or should not put in playbooks.
If you are able to use it again in another project place it in a role. If you can't and it's just a one-time thing put it in a playbook.
That is it fo today,
As always,
Have fun!