RH294 Ch 6: Loops, Conditions, Handlers and Errors

The project in `~/ansible` is ready (groups `dev`=node1, `test`=node2, `prod`=node3). Control which tasks run, when services restart, and how failures are handled.

Tasks

  1. Write ops.yml (all hosts) that creates the users ops1, ops2 and ops3 with a single task using loop; ops1 and ops2 are also in group wheel.
  2. In a play for all hosts, create /etc/dev-only (any content) only on hosts in group dev, using when with groupnames.
  3. Write apache.yml for test: install httpd, deploy /etc/httpd/conf.d/security.conf containing ServerTokens Prod, start and enable httpd. The config task must notify a handler that restarts httpd.
  4. Write recover.yml for prod with a block that runs /usr/local/bin/app-check (it does not exist, so it fails), a rescue that writes recovered to /etc/app-status, and an always that writes checked to /etc/app-audit. The playbook must finish successfully.
  5. Write report.yml for dev: run systemctl is-active sshd registered as sshstate with changedwhen: false and a failedwhen that fails if the output is not active; run ls /nonexistent with ignoreerrors: true; then write sshd=<sshstate.stdout to /etc/report.txt.