Bootstrap FreeKB - Ansible - Install a collection using the ansible-galaxy collection install command
Ansible - Install a collection using the ansible-galaxy collection install command

Updated:   |  Ansible articles

The ansible-galaxy install command can be used to:

In this example, the ansible.posix collection is installed. Notice that by default, the collection is installed to the users collections directory (/home/john.doe/.ansible/collections).

~]$ ansible-galaxy collection install ansible.posix
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Installing 'ansible.posix:1.2.0' to '/home/john.doe/.ansible/collections/ansible_collections/ansible/posix'
Downloading https://galaxy.ansible.com/download/ansible-posix-1.2.0.tar.gz to /home/john.doe/.ansible/tmp/ansible-local-15258q2alfwvq/tmpdesamf4k
ansible.posix (1.2.0) was installed successfully


The -p or --collections-path option can be used to specify the installation directory. In this example, the ansible.posix collection will be installed to /usr/local/ansible/collections/ansible_collections/ansible/posix.

ansible-galaxy collection install ansible.posix --collections-path /usr/local/ansible/collections

 

In this scenario, it probably makes the most sense to append /usr/local/ansible/collections/ansible_collections/ansible/posix to the library directive ansible.cfg.

library = /usr/local/ansible/collections/ansible_collections/ansible/posix

 

The requirements.yml file can be used to install one or more collections. For example, let's say requirements.yml has the following.

---
collections:
  - ansible.posix
  - community.general

 

The version option can be used to specify a specific version to install.

---
collections:
  - ansible.posix

  - community.general
    version: ">=7.2.0"

 

You would then use the ansible-galaxy collection install command with the -r or --requirements-file option following by the path to your requirements.yml file.

ansible-galaxy collection install --requirements-file requirements.yml

 

You may need to use or update a token. Log into https://galaxy.ansible.com, select Collections > API Access and Load Token. Then you can try to install the collection with the --token option.

ansible-galaxy collection install ansible.posix --token <your token>

 

You can can put the token in your /home/your_username/.ansible/galaxy_token file.

]$ cat /home/jeremy.canfield/.ansible/galaxy_token
token: <your token>

 

Or like this, in ansible.cfg.

[galaxy]
server_list = release_galaxy

[galaxy_server.release_galaxy]
url=https://galaxy.ansible.com/
token=<your token>

 

Then the ansible-galaxy collection list command can be used to list the installed collections.

~]$ ansible-galaxy collection list

# /home/john.doe/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
amazon.aws        6.1.0
community.docker  1.9.0
community.general 4.0.2

# /usr/share/ansible/collections/ansible_collections
Collection               Version
------------------------ -------
redhat.rhel_system_roles 1.0.1

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 6b5588 in the box below so that we can be sure you are a human.