Learning Through the Web: Ansible
This list is a companion to my article Learning Through the Web: Lessons Learned
As mentioned in the article, during the learning period I get through, I try to read a relevant book and spot the things I missed on the web. This list is exactly this for ansible. The book read is Ansible Up and Running [1]
- Firstly something that comes handy, you can make your Ansible playbooks executable
- using shebang by adding #! /usr/bin/env ansible-playbook at the beginning of the file
- It is a good practice to keep files and jinja templates on separate directories (/files, /templates)
- because during the execution of each respective task, (file or template)
- ansible will check those directories first, either it is in a role or simply a playbook
- Handlers in ansible run only on changed task status, not always
- default/main.yml variables are meant to be overridden whereas vars/main.yml are not
- You can define dependencies between roles
- You can pass roles variables using the following syntax
roles:
- { role: ntp, ntp_server=ntp.ubuntu.com } - Ansible uses ssh connections, it uses 2 ssh connections per task,
- one to copy the file on the host a second one to execute it
- You can reduce the number of ssh connections, hence the required execution time,
- using pipelining, use one connection to copy and execute the script
- You can further reduce the execution time by reducing the number of TCP connections
- using ssh multiplexing, which will use the same TCP connection to pass all the ssh
- connections through it
- Ansible gathers metadata about each host, those metadata in ansible terms are called facts.
- You can further reduce the execution time by enabling facts caching
- Ansible import is a pseudo import, it will copy all the reference in the file and it will make
- an uber file that will contain everything, pretty much as c does
References
[1] Ansible: Up and Running: Automating Configuration Management and Deployment the Easy Way, Lorin Hochstein