EX294 3.4: Deploying files to managed nodes
Copy a file from the project to the webservers with a backup, make a directory and write a file from inline content, and fetch a file back from every node.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1) with an SSH key, and installs ansible-core. Work as greg,
in /home/greg/ansible: its ansible.cfg reads the inventory inventory,
whose group webservers holds both nodes, logs in as devops and becomes
root.
The managed nodes node1 (10.99.1.11) and node2 (10.99.1.12) are
AlmaLinux 10 containers reached over SSH by name. On each, devops has
greg's key and passwordless sudo, and /etc/issue.net is the old one,
owned by ansible with mode 0600. SELinux is off inside the nodes, so
ls -lZ shows no etc_t there. For a root shell on a node,
sudo podman exec -it node1 bash.
Tasks
- Deploy
/etc/issue.netto the webservers from a file in your project (such asfiles/issue), owned by root, mode 0644, keeping a backup of the old one. Change the source and run it again: another backup appears. - On the webservers, create
/srv/app/confowned bydevopswith mode 0750, and writeapp.confinside it from inline content. - Fetch
/etc/hostnamefrom every webserver intofetched/in the project, so thatfetched/node1/etc/hostnameandfetched/node2/etc/hostnameexist on the control node.
Hints
ansible.builtin.copywithsrc,dest,owner,group,modeandbackup: true;--diffshows what changes.ansible.builtin.filewithstate: directory;copywithcontent.ansible.builtin.fetchwithdest: fetched/.ansible webservers -a 'stat -c "%U %a" /srv/app/conf'andansible webservers -a 'ls -l /etc'check your work.