jlozadad
Mission Specialist
Mission Specialist
  • 970 Views

Re: Ansible Tips and Tricks

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.

Reply
Loading...
WilliamG
Cadet
Cadet
  • 944 Views

Re: Ansible Tips and Tricks

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
Reply
Loading...
DanK
Moderator
Moderator
  • 941 Views

Re: Ansible Tips and Tricks

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
Reply
Loading...
Join the discussion
You must log in to join this conversation.