iac.htora.dev · security templates

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

  1. An inventory lists machines. A playbook lists steps. A role bundles steps to reuse.
  2. Each step describes the state you want, and reports ok, changed, or failed.
  3. A second run of the same playbook reports changed=0.
  4. Handlers run only when something changed. Use them for reloads and restarts.

Commands

Reach every machineansible all -i inventory.ini -m ping
Previewansible-playbook -i inventory.ini site.yml --check --diff
Runansible-playbook -i inventory.ini site.yml
One group onlyansible-playbook -i inventory.ini site.yml --limit web
Read an encrypted fileansible-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.

Read the full pageDownload PDF

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.