Does anyone have any useful or clever Ansible tricks that you routinely use in the course of your normal daily activities?
Of the things I do is always try to have the correct directory structure as mentioned in https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#directory-layout. By having your directory structure as this its easy to switch over to using Ansible Tower. Now that varies depending how your team handles everything but, its a good start. Another thing is using `ansible galaxy init "role name"` to create my roles directory structure. You can create this manually but, this tool auto generates them.
Depending on the purpose of the playbook, sometimes i like to make hosts a variable like:
hosts: ' {{ hosts }}'
I then can call the playbook and pass in the host/group i want to apply it too.
ansible-playbook playbook.yml --extra-vars "hosts=Host-GroupName"
TO accomplish the same thing - what I've done in the past is set hosts to "all":
hosts: all
I then use ansible-playbook with the "--limit" option, which limits the machines in the inventory. It would change your invocation to:
ansible-playbook playbook.yml --limit=Host-GroupName"
This results in a more readable, understandable playbook.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.