Henry_Maine
Flight Engineer Flight Engineer
Flight Engineer
  • 7,077 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
jlozadad
Mission Specialist
Mission Specialist
  • 1,234 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
  • 1,208 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"

 

 

0 Kudos
DanK
Moderator
Moderator
  • 1,205 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.

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