1.8 KiB
EX294 1.1: Inventories, modules and ad hoc commands
Write an inventory with two groups, reach every host with the ping module, install a package with an ad hoc command, and pick hosts with a pattern.
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 file inventory, which doesn't exist yet, and logs in as
ansible. Answers go in /root/lab-answers/<task>, which the lab creates;
write them as root.
The managed nodes node1, node2 and node3 (10.99.1.11 to .13) 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. For a root shell on a node,
sudo podman exec -it node1 bash.
Tasks
- Write the inventory
/home/greg/ansible/inventorywithnode1andnode2in the groupwebserversandnode3indbservers, and show it as a tree. - Run the ping module against every host; each must answer
pong. - Install the
treepackage on the webservers with an ad hoc command, then run the same command again: the first run says CHANGED, the second SUCCESS.ansible webservers -a 'rpm -q tree'finds it. - List the hosts matched by
all:!dbserverswithout running anything, and write the hosts it shows to/root/lab-answers/4.
Hints
ansible-inventory -i inventory --graph.ansible all -m ansible.builtin.ping.ansible webservers -m ansible.builtin.dnf -a 'name=tree state=present'needs-bto become root.--list-hosts; quote the pattern so the shell leaves the!alone. Root can run Ansible from greg's project too:cd /home/greg/ansible && ansible ... >/root/lab-answers/4.