How can I install galaxy collections in awx? - ansible

I use a plugin such as nginx in ansible playbook.
https://galaxy.ansible.com/nginxinc/nginx_core
On server I can use cli to install the roles and collections as
ansible-galaxy collection install nginxinc.nginx_core
But how can I install it on AWX(Tower)?
I tried to run the command in one of AWX container - awx-ee (others are awx-web, awx-task, redis). When run a template in AWX, it still caused a role not found error.

In addition to #Zeitounator comment, you could also manually install your collection into a dedicated path (i.e into collections folder from awx directory)
If you use a requirements.yml file :
sudo -u awx_user ansible-galaxy collection install -r /var/lib/awx/projects/my_project/collections/requirements.yml -p /var/lib/awx/projects/my_project/collections
or manually
ansible-galaxy collection install ansible.my_collection -f
'/home/.ansible/collections/ansible_collections/ansible/my_collection'

Related

How can I avoid getting a .travis.yml file automatically created inside my ansible role?

I have created several roles with ansible-galaxy init my_role and after a while I realized a .travis.yml file was created automatically for a basic syntax testing. I am not planning to use Travis CI, so this .travis.yml file is useless.
I am sure there is a good reason why this occurred, so if you may also explain it I would be thankful.
This is the file:
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
It's part of the default role skeleton. If you want to use a different skeleton, pass it to ansible-galaxy using the --role-skeleton flag:
ansible-galaxy init --role-skeleton ~/ansible-skeletons/role roles/foo

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

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 ?
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/
AFAIK, installation from archives was never support for roles but was supported for collections.
For roles you are stuck with installation from git URLs.
This alone is a good-enough reason for me to avoid using old standalone roles, especially as support for them in galaxy is minimal, no new features being added (like install from tar archives).

Ansible: installing roles in requirements file upon playbook execution

Vagrant has a very nice feature called galaxy_role_file that allows one to point to a requirements.yml file and to install the roles listed there upon vagrant up (provided that the vm is configured to use ansible provisioner).
My question is whether there is such an option in ansible itself, given that I was unable to find it available configurations.
or do we always have to explicitly type ansible-galaxy install -r requirements.yml before each first playbook execution?

Best way to manage local changes to Ansible Galaxy role

I am fairly new to Ansible. I am using a couple of Ansible roles that need some tweaking of specific tasks to work on CentOS 7. What is the best workflow to handle local changes to Ansible-Galaxy roles?
Here are the options I am considering:
Fork the role and make change. Downside is that I would lose the ability to grab dependencies by running Ansible-Galaxy install -r requirements.txt
File an issue with the developer on github. Downside is they may never accept my change or may take several days/weeks.
Make changes locally. Downside is I wont be able to update roles from galaxy without losing my local changes.
After reading the documentation for the ansible-galaxy command I realized I could be pointed directly at my github fork and not affect the ability to grab dependencies using Ansible-Galaxy install -r requirements.txt.
Example: Adding a github repo to requirements.yml:
# from GitHub
src: https://github.com/bennojoy/nginx

Install and Configure Ansible on AWS EC2 Redhat Instance

I have just started learning Ansible configuration management tool and I was going through Linux Academy tutorials to run implement ansible commands, everything was good and easy with the linux-academy servers but when I tried to replicate the same in AWS EC2 instance i was unable to locate the "cd /etc/ansible/hosts". I have installed ansible using pip command i.e., "$sudo pip install ansible". I have been tried to resolve the issue but unable to find any proper documentation. The links I tried to install and configure ansible are as follows:
http://docs.ansible.com/ansible/intro_installation.html
http://www.cyberciti.biz/python-tutorials/linux-tutorial-install-ansible-configuration-management-and-it-automation-tool/
Guide me to configure the ansible hosts path to run the ansible commands and playbooks according to my requirements.
If you are using Ubuntu EC2 instance, follow this:
http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-apt-ubuntu
If you are using Amazon Linux EC2 instance, follow this:
http://docs.ansible.com/ansible/intro_installation.html#latest-release-via-yum
Installing via these package managers will create the /etc/ansible/hosts file for you.
Steps to install Ansible on EC2 instance [RHEL-8]:
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf config-manager --set-enabled codeready-builder-for-rhel-8-rhui-rpms
dnf install ansible
ansible --version
Use dnf for faster dependency resolution.

Resources