/ ansible

Ansible Gotchas, Tricks, and Tools [Part 1]

I have been working with Ansible for some time now. I have come to like the simplicity of the approach and its capabilities. In this series of posts, I hope to document some of the personal discoveries I have had. Some of these discoveries might have been in the documentation but had taken me some time to find out.

I will be referencing version numbers from the GitHub repository ansible-gotchas where these versions will reference tags where the sample code can be found.

Please note that to run these playbooks you will need to set 3 servers to play around with. I had done this using AWS. You will need to change any hosts configurations to match yours.

I. Project Structure

I usually have found the best structure to be the following:

ansible-base
|
+-- hosts.d/
|   |
|   +-- group_vars/
|   +-- base
|   +-- dynamic_hosts.py
+-- playbooks/
|   |
|   +-- site.yml
+-- roles/
|   |
|   +-- python/
+-- ansible.cfg
+-- ansible.log
+-- README.md

hosts.d: This is where hosts are kept. Here I usually keep a base file which contains hierarchical information between host groups while allowing placement of dynamic host information to be added.

_group_vars: This is where host group based variables are stored.

playbooks: I usually like to keep all the playbooks in one folder for a given project.

roles: I keep the roles in the same directory of the project. In most cases, I also have a separate playbook that runs first in a given host(master) machine that pulls down the correct version of the roles for me. More on roles later.

ansible.cfg: I almost always create a local ansible.cfg with the configuration below;

[defaults]
roles_path = ../roles:./roles
log_path=project_path/ansible.log

This will allow me to run the playbooks that call the roles either from within the playbook directory or the project directory.

Ok that is it for now,

Watch out for part 2!

John Roach

John Roach

I am John Roach, a devops architect. Find more information here: https://johnroach.io/about/

Read More
Ansible Gotchas, Tricks, and Tools [Part 1]
Share this