Home/Refreshers/Ansible: refresher
Ansible
A tool that logs in to machines you already have, over SSH, and runs a list of steps on each one. Nothing is installed on the machines first.
Remember
- An inventory lists machines. A playbook lists steps. A role bundles steps to reuse.
- Each step describes the state you want, and reports ok, changed, or failed.
- A second run of the same playbook reports changed=0.
- Handlers run only when something changed. Use them for reloads and restarts.
Commands
| Reach every machine | ansible all -i inventory.ini -m ping |
| Preview | ansible-playbook -i inventory.ini site.yml --check --diff |
| Run | ansible-playbook -i inventory.ini site.yml |
| One group only | ansible-playbook -i inventory.ini site.yml --limit web |
| Read an encrypted file | ansible-vault view secrets.yml |
Watch out
- command and shell cannot tell if the work is already done. Use a module, or add changed_when.
- Reload the service you connect through. A restart can cut off your own session.
- ok means a file was written. Read the setting back to prove it took effect.
Check it worked
Run the playbook twice. The second recap ends with changed=0.