1.9 KiB
1.9 KiB
EX294 8.2: Installing roles
Install roles written elsewhere: tarballs from a web server and a role from a Git branch, all from a requirements file, then update one.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1) and installs ansible-core and git. Work as greg, in
/home/greg/ansible: its ansible.cfg reads the inventory inventory,
logs in to the node as devops with greg's SSH key, and becomes root.
- The managed node
node1(10.99.1.11) is an AlmaLinux 10 container running httpd, serving/var/www/html. For a root shell there,sudo podman exec -it node1 bash. /home/greg/role-srchas two roles,motdandissue./srv/git/chrony-role.gitis a Git repository (owned by greg) with a rolechronyon the branchesmainanddevel.
Tasks
- Make a tarball of each role in
~/role-src, serve them from node1 ashttp://node1/roles/motd.tar.gzandhttp://node1/roles/issue.tar.gz, and install both into/home/greg/ansible/roleswith the requirements file/home/greg/ansible/roles/requirements.yml.ansible-galaxy role list -p roleslists them under the project'srolesdirectory. - Install the role
chronyfrom/srv/git/chrony-role.gitat the branchdevel.ansible-galaxy role list -p rolesshowsdevelas its version. - Change the role in its source: clone the repository, commit a change
on
devel, and push it. Then update your installed copy. A plain install skips it;--forcegets the new version.
Hints
- A role tarball has the role's directory at its top:
tar -czf motd.tar.gz -C ~/role-src motd. ansible node1 -m copy -a "src=... dest=/var/www/html/roles/"puts a file on the web server.- In the requirements file, each role has
nameandsrc; a Git source isgit+file:///srv/git/chrony-role.gitwithversion: devel. ansible-galaxy role install -r roles/requirements.yml -p roles.