From 968fdf697e10dbffb6b699d9e643c8cc6c47795b Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Fri, 20 Sep 2019 13:06:36 +0100 Subject: [PATCH] added install_ansible.sh --- setup/install_ansible.sh | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 setup/install_ansible.sh diff --git a/setup/install_ansible.sh b/setup/install_ansible.sh new file mode 100755 index 00000000..a51aa0b5 --- /dev/null +++ b/setup/install_ansible.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# +# Author: Hari Sekhon +# Date: 2019/09/20 +# +# https://github.com/harisekhon/devops-bash-tools +# +# License: see accompanying LICENSE file +# +# https://www.linkedin.com/in/harisekhon +# + +# Installs Ansible on Mac / Linux +# +# https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html + +set -euo pipefail +[ -n "${DEBUG:-}" ] && set -x + +os="$(uname -s)" +echo "OS detected as $os" +echo + +sudo=sudo +[ $EUID -eq 0 ] && sudo="" + +if [ -z "${UPDATE_ANSIBLE:-}" ]; then + if command -v ansible &>/dev/null; then + echo "Ansible already installed" + echo + echo "To update ansible, set the below and then re-run this script" + echo + echo "export UPDATE_ANSIBLE=1" + exit 0 + fi +fi + +echo "Installing Ansible" +echo +if [ "$os" = "Darwin" ]; then + brew update + brew install ansible +elif [ "$os" = "Linux" ]; then + if command -v dnf &>/dev/null; then + $sudo dnf install -y ansible + elif command -v yum &>/dev/null; then + $sudo yum install -y ansible + elif command -v akp &>/dev/null; then + $sudo apk update + $sudo apk add ansible + elif command -v deb &>/dev/null; then + if grep -q Ubuntu /etc/*release; then + $sudo apt update + $sudo apt install software-properties-common + $sudo apt-add-repository --yes --update ppa:ansible/ansible + $sudo apt install ansible + else + # assume Debian + line='deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' + if ! grep -Fq "$line" /etc/apt/sources.list; then + echo "$line" >> /etc/apt/sources.list + fi + $sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 + $sudo apt update + $sudo apt install ansible + fi + elif command -v emerge &>/dev/null; then + $sudo emerge -av app-admin/ansible + elif command -v pip &>/dev/null; then + pip install --user ansible + else + echo "Couldn't find Linux package manager!'" + exit 1 + fi +elif command -v pip &>/dev/null; then + pip install --user ansible +else + echo "Unsupported OS and pip not available!" + exit 2 +fi