Last active
March 31, 2023 10:47
-
-
Save craig-m-unsw/9de150a2f8651fa17dfdb6aff9494ac2 to your computer and use it in GitHub Desktop.
install ansible on Debian/Ubuntu and RedHat/CentOS/Rocky
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# A script to install ansible as per: | |
# https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html | |
# | |
# For Debian/Ubuntu and RedHat/CentOS | |
# | |
# Installation functions | |
# | |
# -- Ubuntu -- | |
install_ansible_ubuntu() { | |
echo "runninng install_ansible_ubuntu"; | |
export DEBIAN_FRONTEND=noninteractive; | |
sudo apt update -q || { echo "ERROR: 'apt update' failed"; exit 1; } | |
sudo apt install -y -q software-properties-common || { echo "ERROR: failed apt install software-properties-common"; exit 1; } | |
sudo apt-add-repository --yes --update ppa:ansible/ansible || { echo "ERROR: failed to add ansible repo"; exit 1; } | |
sudo apt install -y -q ansible || { echo "ERROR: failed to apt install ansible"; exit 1; } | |
} | |
# -- Debian -- | |
install_ansible_debian() { | |
echo "running install_ansible_debian"; | |
export DEBIAN_FRONTEND=noninteractive; | |
sudo apt-get install ansible -y; | |
} | |
# -- RHEL -- | |
install_ansible_rhel() { | |
echo "running install_ansible_rhel"; | |
sudo yum install ansible -y; | |
} | |
# | |
# system checks | |
# | |
# test we can either use sudo, or are running as root. | |
sudo id | grep -q "uid=0(root)" || { echo "ERROR: can not sudo"; exit 1; } | |
# | |
# install Ansible | |
# | |
echo "starting install-ansible.sh" | logger | |
# -- Debian / Ubuntu -- | |
if [ -f "/etc/debian_version" ]; then | |
# try ubuntu first | |
lsb_release -id | grep -q -i ubuntu && install_ansible_ubuntu | |
# try debian | |
lsb_release -id | grep -q -i debian && install_ansible_debian | |
fi | |
# -- RHEL -- | |
if [ -f "/etc/redhat-release" ]; then | |
install_ansible_rhel; | |
fi | |
# test | |
if ! [ -x "$(command -v ansible-playbook --version)" ]; then | |
echo "ERROR: can not execute ansible-playbook - error installing ansible" | |
exit 1; | |
fi | |
# | |
# done | |
# | |
echo "finished install-ansible.sh" | logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment