Ansible versió personalitzada

Script per utilitzar una versió de Ansible i Python específica

#!/bin/bash
TEMPDIR="/tmp/sergi"
PYTHON_VERSION="3.9"
#ANSIBLE_VERSION="v2.9.6"
ANSIBLE_VERSION="v2.15.11"
DIRECTORI_ANSIBLE="$HOME/devel/ansible/"

if [ ! -f "$DIRECTORI_ANSIBLE/ansible-python-${PYTHON_VERSION}/bin/activate" ]; then
        mkdir $DIRECTORI_ANSIBLE/ansible-python-${PYTHON_VERSION}
        python${PYTHON_VERSION} -m venv "$DIRECTORI_ANSIBLE/ansible-python-${PYTHON_VERSION}"
fi

source $DIRECTORI_ANSIBLE/ansible-python-${PYTHON_VERSION}/bin/activate

mkdir $TEMPDIR
cd $TEMPDIR
git clone -b $ANSIBLE_VERSION --recursive https://github.com/ansible/ansible.git $ANSIBLE_VERSION
cd $DIRECTORI_ANSIBLE
source $TEMPDIR/./$ANSIBLE_VERSION/hacking/env-setup
export ANSIBLE_HOME=$DIRECTORI_ANSIBLE
export ANSIBLE_CONFIG=$DIRECTORI_ANSIBLE/config/ansible.cfg
export PYTHONWARNINGS="ignore"

if [ ! -f keys/ansible.rsa ]; then
    echo "No hi ha claus executa: ssh-keygen -t rsa -C 'ansible@vm.test' -f keys/ansible.rsa"
fi

cat  >$ANSIBLE_CONFIG <<EOF
[defaults]

inventory          = $DIRECTORI_ANSIBLE/inventory/hosts
roles_path         = $DIRECTORI_ANSIBLE/roles
log_path           = $DIRECTORI_ANSIBLE/log/ansible.log
library            = $DIRECTORI_ANSIBLE/modules

[inventory]
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
EOF



cd $DIRECTORI_ANSIBLE
pip3 install ansible
ansible --version