added install_ansible.sh

pull/2/head
Hari Sekhon 5 years ago
parent ee5a3d83ac
commit 968fdf697e

@ -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
Loading…
Cancel
Save