How do I install an Ansible Galaxy role from a tar.gz file?

Viewed 3543

I have seen a number of sites that explain how to install a role from a tar.gz file using ansible-galaxy, and they all seem to say the same thing. In my case I have downloaded the following role file from ansible galaxy :

dsglaser-cis_security-1.2.0.tar.gz

Then I tried to install the role:

ansible-galaxy collection install dsglaser-cis_security-1.2.0.tar.gz

which gives me the warning :

[WARNING]: - collection was NOT installed successfully: Failed to get data from the API server (https://galaxy.ansible.com/api/): Failed to connect to galaxy.ansible.com at port 443: [Errno 104] Connection reset by peer

This is correct, because this machine is not, and never will be connected to the internet.

Another attempt :

ansible-galaxy install dsglaser-cis_security-1.2.0.tar.gz

results in another warning:

[WARNING]: - dsglaser-cis_security-1.2.0.tar.gz was NOT installed successfully: the specified roles path exists and is not a directory.

Also tried using the -p option to indicate where I want the role to be installed, with and without the directory present, but every attempt resulted in the last warning.

I'm not doing this as root... Ansible version is 2.8.13

Just discovered that the command

ansible-galaxy install dsglaser-cis_security-1.2.0.tar.gz -p ./bla

does work, but only as root. And that's not what I want...

What am I doing wrong ?

1 Answers

I have been banging my head against the wall on this one for a while. I found that the collections I am trying to install have dependencies, that are not included in the tar.gz file.

This makes galaxy go out to download the files not found.

The way to get around this is by using another machine with ansible (2.10+) and transferring the files over.

Once you have ansible installed on a machine with internet use the following command ansible-galaxy collection download {{ name of collection, if multiple use space as a separator }} i.e.

ansible-galaxy collection download cisco.ios cisco.asa

This will create a folder in your current working directory with a tar.gz of the collection and its dependencies, as well as a requirements.yml file.

Note: with the requirements.yml file, if you re-run the download command, it will overwrite this, so if you have multiple collections use the single line command above.

Then it's just a matter of copying that folder over to the offline ansible server (2.9+), cd to that directory, and run:

ansible-galaxy collection install -r requirements.yml

Bobs your uncle. I hope this saves someone time. Thanks goes to this reddit post on the same topic https://www.reddit.com/r/ansible/comments/lh1do0/ansible_newbie_trying_to_install_an_ansible/

Related