2.1 KiB
EX294 1.3: Plays and playbooks
Write a playbook with two plays, preview a change with check mode, and find a YAML mistake with a syntax check.
Before you start
This VM is the control node. The lab installs ansible-core and creates
the user greg (password Lab-Pass-1), who has an SSH key. Work as greg
(su - greg as root), in /home/greg/ansible: its ansible.cfg reads the
inventory inventory, which has node1 in the group webservers and
node2 in dbservers, and logs in as ansible. Answers go in
/root/lab-answers/<task>, which the lab creates; write them as root.
The managed nodes node1 (10.99.1.11) and node2 (10.99.1.12) are
AlmaLinux 10 containers with their own users and packages, reached over
SSH by name. On each, the user ansible accepts greg's key and may use
sudo without a password. They run no firewall. For a root shell on a node,
sudo podman exec -it node1 bash.
Tasks
- Write
/home/greg/ansible/site.ymlwith one play that installs, starts and enables httpd and writes a home page,/var/www/html/index.html, on the webservers, and another play that installsmariadb-serveron the dbservers. Run it twice: the second run showschanged=0for every host, andcurl http://node1from the control node prints the page (open the firewall if one is running). - Change the page's text in
site.ymland preview the change on node1 only, without making it:--check --diff --limit node1shows the old and the new line, andcurl http://node1still prints the old text. Leave it that way. - Copy
site.ymlto/home/greg/ansible/broken.yml, break the indentation of one task there, and find the error with--syntax-check. Write the line number it names to/root/lab-answers/3.
Hints
- The plays are a YAML list: each starts with
- name:and hashosts:,become: trueandtasks:. ansible.builtin.dnf,ansible.builtin.copywithcontent:anddest:, andansible.builtin.servicewithstate: startedandenabled: true.ansible-playbook site.yml --check --diff --limit node1.ansible-playbook broken.yml --syntax-check; look for "line N" in the error.