>_ IzzyLab

Hands-on task

This task is step 10 of the course “Terraform and Ansible”

Ansible Against localhost

hard~20 min

Infrastructure as code, local edition. Write a playbook /root/site.yml targeting localhost (local connection) that: creates a user deploy, creates the directory /opt/app owned by deploy with mode 750, and writes the line Managed by Ansible into /etc/motd. Run it until it converges. The playbook must set everything up from scratch on a machine where none of it exists yet, and a second run must change nothing.

What you'll practise:
  • ansible
  • iac
  • playbook
  • idempotency
  • modules

Topic breakdown

Ansible is a configuration-management tool built on the IaC principle: you describe the desired system state in a playbook (YAML), and the engine brings the machine to it on its own through specialized modules (user, file, copy, etc.). Ansible usually reaches hosts over SSH, but the target can be pointed at the machine itself by setting hosts: localhost and connection: local in the play — then no inventory is needed. The key property of modules is idempotency: a repeated run doesn't break the state already reached but shows changed=0, which is exactly what convergence means.

What's checked

  1. the playbook sets everything up from scratch
  2. user deploy created
  3. /opt/app is owned by deploy with mode 750
  4. /etc/motd contains Managed by Ansible
  5. a second run changes nothing (changed=0)

What it looks like