cancel
Showing results for 
Search instead for 
Did you mean: 
Henry_Maine
Flight Engineer Flight Engineer
Flight Engineer
  • 13.4K Views

Ansible Tips and Tricks

Does anyone have any useful or clever Ansible tricks that you routinely use in the course of your normal  daily activities?

22 Replies
aoyawale
Mission Specialist
Mission Specialist
  • 2,064 Views

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.

WilliamG
Cadet
Cadet
  • 2,038 Views

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"

 

 

DanK
Moderator
Moderator
  • 2,035 Views

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.

Join the discussion
You must log in to join this conversation.