How to configure AWX for using an unreleased version of Ansible - ansible

I have installed AWX using the galaxy role obtained with ansible-galaxy install geerlingguy.awx.
It installs the devel branch of awx, however jobs still use the stable version of ansible.
Is there a way to control the version of ansible used by jobs when running playbooks from AWX?

I solved the issue leveraging virtualenvs as per an hint from https://groups.google.com/forum/#!topic/awx-project/AlWbCrlpIC0
So it was a matter of creating a virtualenv on docker containers and enabling it for the organization:
docker exec -it awx_web bash
virtualenv /var/lib/awx/venv/ansible27
yum install -y gcc
yum install -y python-devel
/var/lib/awx/venv/ansible27/bin/pip install python-memcached psutil
/var/lib/awx/venv/ansible27/bin/pip install -U "ansible == 2.7.0"
exit
docker exec -it awx_task bash
virtualenv /var/lib/awx/venv/ansible27
yum install -y gcc
yum install -y python-devel
/var/lib/awx/venv/ansible27/bin/pip install python-memcached psutil
/var/lib/awx/venv/ansible27/bin/pip install -U "ansible == 2.7.0"
exit
curl -u 'admin:password' -X PATCH -H 'Content-Type: application/json' http://127.0.0.1/api/v2/organizations/MYORG/ -d '
{
"custom_virtualenv": "/var/lib/awx/venv/ansible27"
}
'

Related

Install Ansible on CentOS 8 if you get ansible-core >= 2.12.2 with ansible-core < 2.13

In order to install Ansible on Centos 8; epel-release package needs to be installed. Due to Centos8 end of life, no new packages and security updates are not maintained and all repos has moved under vault.centos.org thus CentOS-* repos need to replace then we can install epel-release. Once you install epel-release ansilbe installation gives below error since June 2022.
nothing provides (ansible-core >= 2.12.2 with ansible-core < 2.13) needed by ansible-5.4.0-2.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
The solutions for that I have created a small script it changes centos-repos and install epel-relase then changes epel's repo and install Ansible 2.9.27-1.el8 with all dependencies.
#!/bin/bash
set -ex
# Add EPEL repository
osV=$(rpm --eval '%{centos_ver}')
if [ "$osV" == "8" ]; then
cd /etc/yum.repos.d/
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sudo yum install -y epel-release
sudo sed -i 's/metalink/#metalink/g' /etc/yum.repos.d/epel*
sudo sed -i 's|#baseurl=https://download.example/pub/|baseurl=https://mirror.init7.net/fedora/|g' /etc/yum.repos.d/epel*
else
sudo yum install -y epel-release
fi
sudo yum install -y ansible
I also stucked by this question,and centos version was 8.5.2111 (not centos stream)
and i just manually download ansible-core.rpm and it's dependency and install them,
then i can install the ansible by dnf install ansible
the detail step was:
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/ansible-core-2.12.2-3.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/aarch64/os/Packages/python38-resolvelib-0.5.4-5.el8.noarch.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/sshpass-1.09-4.el8.x86_64.rpm
rpm -ivh python38-resolvelib-0.5.4-5.el8.noarch.rpm
rpm -ivh sshpass-1.09-4.el8.x86_64.rpm
rpm -ivh ansible-core-2.12.2-3.el8.x86_64.rpm

How to avoid installing all centos packages everytime I run gitlab ci pipeline?

I'm running a gitlab ci pipeline with a Centos image.
The pipeline has a before script that runs a set of commands.
gitlab-ci.yaml
variables:
WORKSPACE_HOME: '$CI_PROJECT_DIR'
DELIVERY_HOME: delivery
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
default:
image: centos:latest
cache:
paths:
- .cache/pip
before_script:
- chmod u+x devops/scripts/*.sh
- devops/scripts/install-ci.sh
- python3 -m ensurepip --upgrade
- cp .env.docker.dist .env
- pip3 install --upgrade pip
- pip3 install -r requirements.txt
install-ci.yaml
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-* &&\
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
yum -y update
yum -y install gcc gcc-c++ make
yum -y install python3.8
yum install python3-setuptools
yum -y groupinstall "Development Tools"
yum -y install python3-devel
yum -y install postgresql-server
yum -y install postgresql-devel
yum -y install postgresql-libs
yum -y install python3-pip
timedatectl set-timezone Europe/Paris
yum -y install sqlite-devel
The issue is that everytime I run the ci pipeline it takes time to install centos and all it's packages.
Is there a way to avoid this ? or cache this operation somewhere ?
You could create your own image in which all your dependencies are installed and use this in your job instead of installing the dependencies all over again. I would create a dedicated project on your gitlab instance, something like "centos-python-postgress" and within this project you create a Dockerfile in which you install everything you need. (You can either copy your install-ci.sh or RUN the commands directly within your dockerfile) :
FROM centos:latest
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-* && sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
RUN yum -y update
RUN yum -y install gcc gcc-c++ make
...
You can now either build the Dockerfile on your machine and push it manually to the container registry in this project or you create a CI Pipeline that builds and pushes that image automatically:
stages:
- build
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- >-
/kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}:latest"
Now, Instead of using centos:latest in your origin project/job, you can use your own image:
variables:
WORKSPACE_HOME: '$CI_PROJECT_DIR'
DELIVERY_HOME: delivery
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
default:
image: registry.gitlab.com/snowfire/centos-python-postgress:latest
cache:
paths:
- .cache/pip
before_script:
- ...

Error running docker-compose command via Ansible playbook

I am getting an error trying to execute docker-compose in a ansible playbook.
I am running from a Mac OSX, but the destination node is a AWS ec2 (Ubuntu 20.04)
On Ubuntu 20.04, I installed the following
sudo apt-get update -y && sudo apt-get install git python3 python3-setuptools
python3-pip software-properties-common docker docker.io unzip acl -y
sudo apt-add-repository -y --update ppa:ansible/ansible
sudo apt-get install ansible -y
sudo apt install python3-pip -y
sudo apt-get install python3-docker
pip3 install docker
pip3 install docker-compose
In the main.yml
name: Run "docker-compose up"
community.docker.docker_compose:
project_src: /data
project_name: test
register: output
I am getting the following error
fatal: [ndr2]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: Traceback (most recent call last):\n File \"/tmp/ansible_community.docker.docker_compose_payload_566twi2g/ansible_community.docker.docker_compose_payload.zip/ansible_collections/community/docker/plugins/modules/docker_compose.py\", line 494, in <module>\nModuleNotFoundError: No module named 'compose'\n"}
Any help is appreciated.
I had to run sudo apt install docker-compose -y on the target host, instead of installing docker-compose via pip3. Not sure why it had to be installed this way.

Install python 3.6 in Ubuntu

I'm running some Python script in my bitbucket pipeline.
where it's running in Ubuntu version 16.04.
following is my script.
add-apt-repository ppa:deadsnakes/ppa -y && apt-get update
apt-get -y install python3.6
apt-get -y install python3-pip
pip3 install tq1
pip3 install zstd
When trying to print
python3 -V
it's returning
Python 3.5.2.
Why it's not Python 3.6.x ?
Please note I must need Python 3.6 to run tq1.
It's a script on your device, right? Can't you just edit the lines?
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt-get update
sudo apt-get -y install python3.6 python3-pip
pip3 install tq1 zstd
Also, you don't need a script to install those. They're just bash commands. You can just type them line-by-line into the terminal...
Check the image on your pipeline, because if you install python 3.6 in one step and execute the python3 -V command in another, it will take the version of the image, not the one from the previous step, since they are in a different container, it would be helpful if you show us the rest of the pipeline

How to install ansible on amazon aws?

Having trouble running Ansible on the latest version of amazon linux.
[root#ip-10-0-0-11 ec2-user]# yum install ansible --enablerepo=epel
[root#ip-10-0-0-11 ec2-user]# ansible-playbook
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 44, in <module>
import ansible.playbook
ImportError: No module named ansible.playbook
Using AMI ID: ami-a10897d6.
Any ideas?
It appears that python library files do not have correct permissions by default. Running this fixed it for me.
[root#ip-10-0-0-11 ansible]# pip install ansible
Using pip (alone, not in conjunction with yum) is probably the best option right now on Amazon Linux. I'd suggest getting rid of the yum-installed copy if it's still there.
The RPM specs in epel and epel-testing (as of 1.9.2) currently handle only RHEL, Fedora, and SuSE, and the defaults are installing everything under Python 2.6, where the latest Amazon Linux has default Python 2.7. A bit of work will be required to get the RPM install working under Amazon Linux...
For Amazon Linux2 AMI:
sudo yum update
sudo yum install ansible
or
sudo amazon-linux-extras install ansible2
For Amazon Linux AMI:
sudo yum update
sudo yum install ansible --enablerepo=epel
For Ubuntu 18.04 AMI:
sudo apt-get update
sudo apt-get install ansible
Note: You can install ansible using "pip".
sudo yum install python-pip
sudo pip install ansible
Why not check out the source code from git and and checkout the latest stable version.
git clone git://github.com/ansible/ansible.git --recursive
$ cd ./ansible
$ source ./hacking/env-setup
git checkout <VERSION>
Just enable the below repo from the /etc/yum.repos.d/redhat-rhui.repo file by default is disabled.
rhui-REGION-rhel-server-extras/7Server/x86_64
This article says that you can use sudo amazon-linux-extras install ansible2 to install ansible on Amazon linux.
On Amazon Linux 2 to get the latest version of Ansible do not use yum (currently it won't give you 2.10.x), I recommend you use python3-pip.
sudo yum remove ansible
sudo yum install -y python3-pip
python3 -m pip install --user --upgrade pip # Do not run pip as sudo. Do this instead.
python3 -m pip install ansible
If you don't already have python3 you may need this step before the above:
sudo yum install -y python3.7
In my case, I needed ansible 2.10.x because it has the added benefit of requirements.yml files being able to install collections directly from git repositories.
This answer is based off of #M.Rajput's answer. I wanted to define the details so I wouldn't forget.
Warning: this was only tested on a RHEL 7.7 Community AMI (ami-029c0fbe456d58bd1).
# modify yum repo enabled
sudo vi /etc/yum.repos.d/redhat-rhui.repo
# find entry titled [rhui-rhel-7-server-rhui-extras-rpms]
# change "enabled=0" to "enabled=1"
# save and quit file (vim command is :wq)
sudo yum install ansible

Resources