RH294 Ch 4: Variables, Facts and Magic Variables

The project in `~/ansible` is ready (groups `dev`=node1, `test`=node2, `prod`=node3). Describe the environment with group and host variables, then use registered results, facts, custom facts and magic variables in playbooks.

Tasks

  1. In ~/ansible/groupvars/, set company: WebAsha for all hosts, and tier to development for dev, testing for test and production for prod.
  2. In ~/ansible/hostvars/, set owner: alice for node1 only.
  3. Write info.yml (all hosts): register the output of uname -r, then create /etc/webasha-info with four lines: company=<company, tier=<tier, host=<short hostname from facts, kernel=<registered stdout.
  4. Write facts.yml that installs a custom fact file /etc/ansible/facts.d/webasha.fact on all hosts with section [app], name=portal, port=8080, so that ansiblelocal.webasha.app.name is portal.
  5. Write hosts.yml that creates /etc/webasha-hosts on node1 only, with one line <IPv4 <hostname for every host in the inventory, using groups['all'] and hostvars (facts must be gathered from all hosts).