Skip to content
Commitpedia
Log in Join & edit

Automate a server with Ansible

Prepare SSH access, write idempotent playbooks with templates and handlers, protect secrets with Vault and manage several servers safely.

Intermediate, 9 steps, about 9 hours

  1. Set up SSH keys: ssh-keygen, ssh-copy-id and ~/.ssh/config Ansible connects over SSH, so key-based login must work first. Article CMP 0053
  2. Users, groups and sudo on Debian, Ubuntu and RHEL Know how sudo works, because most tasks run with become: true. Article CMP 0177
  3. Ansible concepts: inventory, modules, playbooks, idempotency and roles Focus on idempotency; it is what makes repeated runs safe. Article CMP 0181
  4. Ansible ad-hoc commands cheat sheet Test your inventory and connectivity with one-line commands before writing playbooks. Article CMP 0185
  5. Your first Ansible playbook: install nginx and publish a page Write and run a complete playbook, then run it again and see nothing change. Script CMP 0182
  6. Ansible variables, templates and handlers: configure an nginx site Make the playbook reusable with variables and restart services only when needed. Script CMP 0183
  7. Fix: Ansible UNREACHABLE! Failed to connect to the host via ssh The most common first failure; work through the checks in order. Article CMP 0186
  8. Ansible Vault: keep passwords and keys encrypted in your repo Encrypt secrets before the playbooks go into Git. Article CMP 0184
  9. Automate three servers with Ansible: roles, templates, Vault and safe dry runs Capstone: organize everything into roles and roll it out to several servers. Article CMP 0254

Start with step 1