2021-02-25 14:10:17 +00:00
#!/bin/bash -e
# FWIW "-e" tries to exit right away on error:
# https://tldp.org/LDP/abs/html/options.html
# https://stackoverflow.com/questions/9952177/whats-the-meaning-of-the-parameter-e-for-bash-shell-command-line/9952249
2018-04-05 09:29:52 +00:00
2020-09-15 06:31:54 +00:00
# PLZ SEE http://FAQ.IIAB.IO > "What is Ansible and what version should I use?"
2020-09-15 19:27:41 +00:00
# https://github.com/iiab/iiab/tree/master/scripts/ansible.md
2021-02-26 15:29:33 +00:00
# https://github.com/iiab/iiab/wiki/IIAB-Contributors-Guide#ansible
2020-09-15 06:31:54 +00:00
2021-02-25 13:48:44 +00:00
APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint
CURR_VER=undefined # Ansible version you currently have installed
2021-05-25 01:04:21 +00:00
GOOD_VER=2.11.1 # Orig for 'yum install [rpm]' & XO laptops (pip install)
2021-02-25 04:29:59 +00:00
2021-05-19 15:38:58 +00:00
# 2021-05-19 PR #2743: As a result of Ansible / Red Hat / IBM's extensive
# delays in publishing the PPA (.deb installer files) for ansible-core, this
# file bypasses the apt approach (and associated PPA source) in favor of:
#
# pip3 install ansible-core
#
# What the future holds for 2022+ is not yet clear. So the apt approach (with
# PPA source in /etc/apt/sources.list.d and .gpg key etc) and much associated
# guidance/comments below are NOT being commented out or deleted at this time.
2021-04-18 18:12:26 +00:00
# We install the latest 'ansible-core' from PPA, using an OS 'CODENAME' below:
2020-08-21 20:48:32 +00:00
# https://launchpad.net/~ansible/+archive/ubuntu/ansible
2021-02-25 04:29:59 +00:00
# 'lsb_release -sc' gives Mint 20 codename 'ulyana' etc: (TOO FINE-GRAINED)
if grep -q buster /etc/os-release /etc/debian_version; then
CODENAME=bionic # Debian 10, RaspiOS 10 & Buster-like distros
else
CODENAME=focal # Debian 11+, RaspiOS 11+, Ubuntu 20.04+, Mint 20+ (ETC)
fi
2021-05-19 14:14:26 +00:00
# APRIL 2021 - ansible-base (2.10) was renamed to ansible-core (2.11+):
2021-03-07 16:54:17 +00:00
# https://www.ansible.com/blog/ansible-3.0.0-qa
2021-02-25 04:29:59 +00:00
# https://github.com/ansible/ansible/releases
2021-04-18 18:12:26 +00:00
# https://pypi.org/project/ansible-base/
# https://pypi.org/project/ansible-core/
2021-02-25 04:29:59 +00:00
# https://releases.ansible.com/ansible-base/
2021-03-07 16:54:17 +00:00
# https://releases.ansible.com/ansible-core/
2021-04-18 18:12:26 +00:00
# https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.10
# https://launchpad.net/~ansible/+archive/ubuntu/ansible-2.11 ?
# http://ppa.launchpad.net/ansible/ansible/ubuntu/pool/main/a/ansible-base/
# http://ppa.launchpad.net/ansible/ansible/ubuntu/pool/main/a/ansible-core/ ?
# https://github.com/ansible/ansible/blob/stable-2.10/changelogs/CHANGELOG-v2.10.rst
# https://github.com/ansible/ansible/blob/stable-2.11/changelogs/CHANGELOG-v2.11.rst
# https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/roadmap/ROADMAP_2_10.rst
# https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/roadmap/ROADMAP_2_11.rst
2018-09-29 02:35:11 +00:00
2021-05-19 14:17:37 +00:00
# FYI .travis.yml installs ansible-core in a slightly different way (PRs #2689, #2742 or #2743 ?)
2021-02-25 04:29:59 +00:00
2021-04-06 18:26:07 +00:00
# IIAB implementers might instead consider these 4 GENERAL TECHNIQUES below
# ("in an emergency!") e.g. if apt fails & you need a newer/older Ansible:
# TEMPORARILY USE pip3 to install the latest ansible-core as listed at
# https://pypi.org/project/ansible-core/ (REMOVE W/ "pip3 uninstall ansible-core")
2021-05-04 01:00:08 +00:00
#apt install python3-pip
2021-04-06 18:26:07 +00:00
#pip3 install ansible-core # Then start a new shell, so /usr/local/bin works
#apt install python3-pymysql python3-psycopg2 python3-passlib python3-pip python3-setuptools python3-packaging python3-venv virtualenv
#ansible-galaxy collection install -r collections.yml
2020-09-15 19:27:41 +00:00
2021-05-25 01:04:21 +00:00
# TEMPORARILY USE ansible-base 2.10.10 (REMOVE W/ "pip3 uninstall ansible-base")
2021-05-04 00:56:44 +00:00
#apt install python3-pip
2021-05-25 01:04:21 +00:00
#pip3 install ansible-base==2.10.10 # Start new shell, so /usr/local/bin works
2021-02-25 04:29:59 +00:00
2021-05-25 01:04:21 +00:00
# TEMPORARILY USE ANSIBLE 2.9.22 (REMOVE IT WITH "pip uninstall ansible")
2021-05-04 01:00:08 +00:00
#apt install python3-pip
2021-05-25 01:04:21 +00:00
#pip3 install ansible==2.9.22
2020-09-15 19:27:41 +00:00
# TEMPORARILY USE ANSIBLE 2.4.2 DUE TO 2.4.3 MEMORY BUG. Details: iiab/iiab#669
#echo "Install http://download.iiab.io/packages/ansible_2.4.2.0-1ppa~xenial_all.deb"
#cd /tmp
#wget http://download.iiab.io/packages/ansible_2.4.2.0-1ppa~xenial_all.deb
#apt -y --allow-downgrades install ./ansible_2.4.2.0-1ppa~xenial_all.deb
2018-09-07 13:14:08 +00:00
export DEBIAN_FRONTEND=noninteractive
2020-09-15 06:05:55 +00:00
# Why 'noninteractive' appears needed:
# https://github.com/iiab/iiab/issues/564#issuecomment-347264985
2018-04-05 09:29:52 +00:00
2020-09-15 06:17:31 +00:00
echo -e "\n\nYOU ARE RUNNING: /opt/iiab/iiab/scripts/ansible (TO INSTALL ANSIBLE)\n"
2020-09-15 02:02:34 +00:00
#echo -e 'Alternative: /opt/iiab/iiab/scripts/ansible-2.9.x ("Slow Food")\n'
2018-09-25 19:18:13 +00:00
echo -e "RECOMMENDED PREREQUISITES:"
echo -e "(1) Verify you're online"
2020-09-15 06:05:55 +00:00
echo -e "(2) Remove all prior versions of Ansible using..."
2021-04-18 18:12:26 +00:00
echo -e " 'apt purge ansible-core' and/or 'pip3 uninstall ansible-core' and/or"
2021-02-26 15:50:35 +00:00
echo -e " 'apt purge ansible-base' and/or 'pip3 uninstall ansible-base' and/or"
2021-05-04 01:03:49 +00:00
echo -e " 'apt purge ansible' and/or 'pip3 uninstall ansible'"
2020-09-15 06:05:55 +00:00
echo -e "(3) Remove all lines containing 'ansible' from..."
2018-09-25 19:18:13 +00:00
echo -e " /etc/apt/sources.list and /etc/apt/sources.list.d/*\n"
2018-06-27 18:55:19 +00:00
2020-09-15 02:02:34 +00:00
echo -e "IIAB INSTALL INSTRUCTIONS: (OLDER, MANUAL APPROACH)"
2018-09-25 19:02:03 +00:00
echo -e "https://github.com/iiab/iiab/wiki/IIAB-Installation#do-everything-from-scratch\n"
2018-06-27 17:21:00 +00:00
2020-09-15 02:02:34 +00:00
if [ $(command -v ansible) ]; then # "command -v" is POSIX compliant; also catches built-in commands like "cd"
2021-04-13 16:14:27 +00:00
CURR_VER=$(ansible --version | head -1 | cut -f 2- -d " ")
# Above works with 'ansible [core 2.11.0rc2]' -- these old ways do not:
#CURR_VER=$(ansible --version | head -1 | awk '{print $2}')
#CURR_VER=$(ansible --version | head -1 | sed -e 's/.* //')
2018-09-25 20:33:52 +00:00
echo -e "CURRENTLY INSTALLED ANSIBLE: $CURR_VER -- LET'S TRY TO UPGRADE IT!"
2018-09-07 13:14:08 +00:00
else
2018-09-25 20:07:52 +00:00
echo -e "ANSIBLE NOT FOUND ON THIS COMPUTER -- LET'S TRY TO INSTALL IT!"
2018-04-05 09:29:52 +00:00
fi
2021-04-18 18:12:26 +00:00
echo -e "(Internet-in-a-Box requests ansible-core $GOOD_VER or higher)\n"
2018-04-05 09:29:52 +00:00
2020-09-15 19:27:41 +00:00
# Code above designed to work on all Linux distributions, to preserve options,
# in support of any volunteer(s) wanting to port IIAB to a new Linux/distro.
2021-02-26 00:22:38 +00:00
if [ ! -f /etc/debian_version ]; then # e.g. RaspiOS, Ubuntu, Mint & Debian
2020-09-15 02:02:34 +00:00
echo -e "\nEXITING: /etc/debian_version FILE NOT FOUND. Linux OS support info here:"
echo -e " https://github.com/iiab/iiab/wiki/IIAB-Platforms\n"
2018-09-07 13:14:08 +00:00
exit 1
2018-04-05 09:29:52 +00:00
fi
2021-04-26 13:17:31 +00:00
# 2021-04-26: JV & @holta WIP. The apt-key command is going away, and the past
# practice of putting keys in /etc/apt/trusted.gpg.d is considered insecure:
2021-04-26 13:05:37 +00:00
# https://www.linuxuprising.com/2021/01/apt-key-is-deprecated-how-to-add.html
2021-04-27 18:06:44 +00:00
# https://askubuntu.com/questions/1286545/what-commands-exactly-should-replace-the-deprecated-apt-key/1307181#1307181
2021-04-26 13:05:37 +00:00
# So we put .gpg key in repo iiab/iiab, also for reliable installs/containers.
#echo -e "\napt update; install dirmngr; PPA to /etc/apt/sources.list.d/iiab-ansible.list\n"
2021-04-23 00:46:37 +00:00
#$APT_PATH/apt update
2021-04-22 18:38:28 +00:00
#$APT_PATH/apt -y install dirmngr
2021-04-26 13:05:37 +00:00
#echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu $CODENAME main" \
echo "deb [signed-by=/usr/share/keyrings/iiab-ansible-keyring.gpg] http://ppa.launchpad.net/ansible/ansible/ubuntu $CODENAME main" \
2020-09-15 19:32:25 +00:00
> /etc/apt/sources.list.d/iiab-ansible.list
2021-04-26 13:05:37 +00:00
2020-09-15 19:27:41 +00:00
# In future we might instead consider 'add-apt-repository ppa:ansible/ansible'
# or 'apt-add-repository ppa:ansible/bionic/ansible' etc, e.g. for streamlined
# removal using 'apt-add-repository -r' -- however that currently requires
# 'apt install software-properties-common' which drags in a dozen packages we
# might not want, e.g. unattended-upgrades, packagekit etc.
2020-09-15 02:02:34 +00:00
2020-09-15 19:27:41 +00:00
# 2020-08-20: TEMP WORKAROUND (REVERT TO ANSIBLE 2.9.6) MITIGATING
# iiab/iiab#2481 (Ansible 2.9.12 and 2.10.0's 666-TO-600 file permissions
# problem). This workaround installs 2.9.6-1ppa~disco onto RaspiOS, from
# https://launchpad.net/~ansible/+archive/ubuntu/ansible
2020-09-15 02:02:34 +00:00
#echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu disco main" \
2021-04-26 13:05:37 +00:00
# > /etc/apt/sources.list.d/iiab-ansible.list
2020-09-15 02:02:34 +00:00
2021-04-26 13:05:37 +00:00
# 2021-04-26: JV & @holta WIP: (see above)
2021-04-22 18:38:28 +00:00
#echo -e '\nIF YOU FACE ERROR "signatures couldn'"'"'t be verified because the public key is not available" THEN REPEATEDLY RE-RUN "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367"\n'
#apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367
2021-04-26 13:05:37 +00:00
cp /opt/iiab/iiab/scripts/iiab-ansible-keyring.gpg /usr/share/keyrings/iiab-ansible-keyring.gpg
#chmod 644 /usr/share/keyrings/iiab-ansible-keyring.gpg
2020-09-15 02:02:34 +00:00
2021-04-26 13:05:37 +00:00
echo -e 'PPA source "deb [signed-by=/usr/share/keyrings/iiab-ansible-keyring.gpg] http://ppa.launchpad.net/ansible/ansible/ubuntu '$CODENAME' main"'
2020-09-15 02:02:34 +00:00
echo -e "successfully saved to /etc/apt/sources.list.d/iiab-ansible.list\n"
echo -e "IF *OTHER* ANSIBLE SOURCES APPEAR BELOW, PLEASE MANUALLY REMOVE THEM TO"
echo -e 'ENSURE ANSIBLE UPDATES CLEANLY: (then re-run this script to be sure!)\n'
grep '^deb .*ansible' /etc/apt/sources.list /etc/apt/sources.list.d/*.list | grep -v '^/etc/apt/sources.list.d/iiab-ansible.list:' || true # Override bash -e (instead of aborting at 1st error)
2021-04-18 18:12:26 +00:00
echo -e "\napt update; apt install ansible-core and python3 dependencies explained at:"
2021-05-19 15:02:38 +00:00
echo -e "https://github.com/iiab/iiab/blob/master/scripts/ansible.md\n"
2020-09-15 02:02:34 +00:00
$APT_PATH/apt update
2021-04-19 15:41:11 +00:00
$APT_PATH/apt -y install python3-pip
2021-04-19 15:07:50 +00:00
pip3 install ansible-core
#$APT_PATH/apt -y --allow-downgrades install ansible-core \
$APT_PATH/apt -y --allow-downgrades install \
2020-09-15 19:27:41 +00:00
python3-pymysql python3-psycopg2 python3-passlib python3-pip \
2020-10-26 14:26:54 +00:00
python3-setuptools python3-packaging python3-venv virtualenv
2020-09-15 02:02:34 +00:00
2020-11-28 14:15:58 +00:00
# (Re)running collection installs appears safe, with --force-with-deps to force
# upgrade of collection and dependencies it pulls in. Note Ansible may support
2021-02-25 05:00:05 +00:00
# explicit upgrading of collections (--upgrade / -U flag) in version "2.11"
# with PR ansible/ansible#73336. See also IIAB PRs #2647 #2652 #2653 #2655.
2021-01-29 01:26:11 +00:00
echo -e "\n\nIIAB requires these ~4 Ansible Collections: (we upgrade them here if possible!)\n"
2020-11-29 02:18:58 +00:00
ansible-galaxy collection install --force-with-deps \
-r /opt/iiab/iiab/collections.yml \
-p /usr/share/ansible/collections
2021-03-07 17:05:57 +00:00
# 2021-02-24: 'ansible-galaxy collection list' lists those installed. (#2659)
2020-11-29 01:55:20 +00:00
# 2020-11-28: The ~3 Ansible Collections used by IIAB (~37MB) once lived here:
2020-11-28 22:39:00 +00:00
# /root/.ansible/collections/ansible_collections
2021-05-19 19:24:45 +00:00
# But going forward they'll be stored herein: [~24MB for 4 Collections as of 2021-05-19]
2020-11-28 22:39:00 +00:00
# /usr/share/ansible/collections/ansible_collections
2020-09-15 02:02:34 +00:00
2021-05-04 01:07:14 +00:00
# 2021-04-19: No longer needed, per PR #2743 testing
2021-04-19 15:29:42 +00:00
#echo -e "\n\nCreating/verifying directory /etc/ansible & installing /etc/ansible/hosts\n"
#mkdir -p /etc/ansible # LIKELY REDUNDANT, due to above installation of Ansible
#echo -e '[local]\nlocalhost\n' > /etc/ansible/hosts # LIKELY REDUNDANT, due to https://github.com/iiab/iiab/blob/master/ansible_hosts
2020-09-15 19:27:41 +00:00
2021-05-19 16:28:14 +00:00
echo -e "SUCCESS INSTALLING ANSIBLE! PLEASE VERIFY WITH COMMANDS LIKE:"
echo -e " ansible --version"
echo -e " pip show ansible-core"
echo -e " apt -a list ansible-core\n\n"