EX294 8.3: Installing collections
Install collections into your project: one from a tarball on a web server, one from Galaxy at a version your ansible-core supports, and one into a directory Ansible doesn't look in.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1) and installs ansible-core. 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.
It doesn't set collections_path yet.
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. The collections come from Ansible
Galaxy, so the VM needs internet access.
Tasks
- Download
ansible.posixfrom Galaxy as a tarball, serve it from node1 underhttp://node1/collections/, and install it into/home/greg/ansible/collectionsfrom a requirements file withtype: url.ansible-galaxy collection listshows it under the project'scollectionsdirectory. - Install
community.generalat a version that works with your ansible-core, and write/home/greg/ansible/ini.yml, which uses itsini_filemodule to setport = 8080in the section[web]of/etc/lab.inion node1.ansible-doc community.general.ini_fileworks without a warning, and the playbook runs. - Install
community.cryptowith-p /home/greg/elsewhere, a directory that isn't incollections_path. ansible-galaxy warns, and Ansible can't find its modules:ansible-doc community.crypto.openssl_privatekeyfinds nothing.
Hints
ansible-galaxy collection download ansible.posix -p DIR, thenansible node1 -m copyto put it under/var/www/html/collections/.- A collections requirements file starts with
collections:; a tarball entry is- name: URLwithtype: url. collections_path = ./collections:/usr/share/ansible/collectionsinansible.cfg, thenansible-galaxy collection install -r FILE -p collections.ansible --versionshows your ansible-core; a collection'smeta/runtime.ymlhasrequires_ansible. Galaxy doesn't check it, so pin a version:version: "<12".