Skip to content

Instantly share code, notes, and snippets.

@zoredache
Last active December 1, 2023 09:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zoredache/5ccf8785d12cd3af0f5ef1feae79f704 to your computer and use it in GitHub Desktop.
Save zoredache/5ccf8785d12cd3af0f5ef1feae79f704 to your computer and use it in GitHub Desktop.
install_ansible.sh Debian/Ubuntu
#!/bin/bash
set -euo pipefail
set -x
virtualenv_path=/usr/local/ansible/stable
# Install packages needed on a base Debian system
apt-get update
</dev/null DEBIAN_FRONTEND=noninteractive \
apt-get --yes install --no-install-recommends $(
echo "build-essential
krb5-user
libkrb5-dev
libyaml-dev
lsb-release
python3-dev
python3-netaddr
python3-pip
python3-setuptools
python3-wheel
python3-venv
sshpass" )
mkdir -p /etc/ansible
mkdir -p ${virtualenv_path}
# Create requirements file for pip
echo "
ansible
ansible-cmdb
ansible-core
ansible-lint
bcrypt
cryptography
dnspython
docker
jmespath
netaddr
ntlm-auth
paramiko
pykerberos
pyOpenSSL
pypsrp
pywinrm
requests
requests-credssp
requests-kerberos
six
yamllint
" > ${virtualenv_path}/requirements.txt
# Create virtual environment we we install ansible into
if test ! -x ${virtualenv_path}/bin/pip ; then
/usr/bin/python3 -m venv ${virtualenv_path}
fi
# Upgrade pip
${virtualenv_path}/bin/pip install --upgrade pip
# install/upgrade ansible in the virtual environment
${virtualenv_path}/bin/pip install --upgrade --requirement ${virtualenv_path}/requirements.txt
# create some symlinks in /usr/local/bin for the commands in our venv
# so we can use them without activating the venv
while read item;
do
if test ! -x /usr/local/bin/${item} ; then
ln -rs ${virtualenv_path}/bin/$item /usr/local/bin/$item
fi
done <<EOF
ansible
ansible-config
ansible-connection
ansible-cmdb
ansible-doc
ansible-galaxy
ansible-inventory
ansible-lint
ansible-playbook
ansible-pull
ansible-test
ansible-vault
yamllint
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment