mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
Merge pull request #509 from holta/master
iiab-install: checks Ansible version & explains what it's doing
This commit is contained in:
commit
47e69c55aa
3 changed files with 101 additions and 60 deletions
129
iiab-install
129
iiab-install
|
@ -1,90 +1,131 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
# running from a git repo
|
# Running from a git repo
|
||||||
# Add cmdline options for passing to ansible
|
# Add cmdline options for passing to ansible
|
||||||
# todo add proper shift to gobble up --debug --reinstall
|
# Todo add proper shift to gobble up --debug --reinstall
|
||||||
ARGS=""
|
|
||||||
OLD_RPI_KERN="4.9.41-v7+"
|
if [ "$1" != "--debug" ] && [ "$1" != "--reinstall" ] && [ "$1" != "" ]; then
|
||||||
|
echo "Use './iiab-install' for regular installs, or to continue an install."
|
||||||
|
echo "Use './iiab-install --reinstall' to force running all Stages 0-9."
|
||||||
|
echo "Use './iiab-install --debug' to run Stage 0, followed by Stages 3-9."
|
||||||
|
echo "Use './runtags' to run a single Stage or Tag or Role."
|
||||||
|
echo "Use './iiab-network' to run Network sections."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
PLAYBOOK="iiab-stages.yml"
|
PLAYBOOK="iiab-stages.yml"
|
||||||
INVENTORY="ansible_hosts"
|
INVENTORY="ansible_hosts"
|
||||||
|
ARGS=""
|
||||||
CWD=`pwd`
|
CWD=`pwd`
|
||||||
OS=`grep ^ID= /etc/*release|cut -d= -f2`
|
OS=`grep ^ID= /etc/*release|cut -d= -f2`
|
||||||
OS=${OS//\"/}
|
OS=${OS//\"/}
|
||||||
|
MIN_RPI_KERN=4.9.59-v7+
|
||||||
function version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; }
|
MIN_ANSIBLE_VER=2.4.1.0
|
||||||
|
|
||||||
export ANSIBLE_LOG_PATH="$CWD/iiab-install.log"
|
export ANSIBLE_LOG_PATH="$CWD/iiab-install.log"
|
||||||
|
|
||||||
if [ ! -f $PLAYBOOK ]; then
|
if [ ! -f $PLAYBOOK ]; then
|
||||||
echo "IIAB Playbook not found."
|
echo "EXITING: IIAB Playbook not found."
|
||||||
echo "Please run this command from the top level of the git repo."
|
echo "Please run 'iiab-install' from /opt/iiab/iiab (top level of git repo)."
|
||||||
echo "Exiting."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $OS == "raspbian" ]; then
|
# Subroutine compares software version numbers. Generates rare false positives
|
||||||
echo "Found Raspbian"
|
# like "1.0 > 1" and "2.4.0 > 2.4". Avoid risks by structuring conditionals w/
|
||||||
CURRENT_KERN=`uname -r`
|
# a consistent # of decimal points e.g. "if version_gt w.x.y.z a.b.c.d; then"
|
||||||
if version_gt $CURRENT_KERN $OLD_RPI_KERN ; then
|
function version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; }
|
||||||
echo "Kernel looks ok - continuing"
|
|
||||||
else
|
# Verify that Raspbian is running a recent enough kernel. As Raspbian
|
||||||
echo "Kernel "$CURRENT_KERN" is too old. Before running './iiab-install' you first need"
|
# updates on 4.9.41-v7+ broke bridging, WiFi AP & OpenVPN in Oct/Nov 2017.
|
||||||
echo "to update your system with 'apt update' then 'apt dist-upgrade' then reboot."
|
CURR_KERN=`uname -r`
|
||||||
echo "INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
|
echo "Found Kernel "$CURR_KERN""
|
||||||
exit 1
|
if [ "$OS" == "raspbian" ] && version_gt $MIN_RPI_KERN $CURR_KERN; then
|
||||||
fi
|
echo -e "\nEXITING: Kernel "$MIN_RPI_KERN" or higher required with Raspbian."
|
||||||
|
echo "PLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot."
|
||||||
|
echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify that a recent enough version of Ansible is installed. See #449. The
|
||||||
|
# "include:" command was inconsistently implemented prior to Ansible 2.4.x.x
|
||||||
|
CURR_ANSIBLE_VER=0
|
||||||
|
if [[ `type -P ansible` ]]; then
|
||||||
|
CURR_ANSIBLE_VER=`ansible --version | head -1 | sed -e 's/.* //'`
|
||||||
|
echo "Found Ansible "$CURR_ANSIBLE_VER""
|
||||||
|
fi
|
||||||
|
if version_gt $MIN_ANSIBLE_VER $CURR_ANSIBLE_VER; then
|
||||||
|
echo -e "\nEXITING: Ansible "$MIN_ANSIBLE_VER" or higher required."
|
||||||
|
echo "PLEASE RUN './scripts/ansible' to install the latest Ansible from PPA or RPM."
|
||||||
|
echo "'ansible --version' and 'apt -a list ansible' can also be useful here. Try"
|
||||||
|
echo "to remove prior versions with 'apt purge ansible' or 'pip uninstall ansible'."
|
||||||
|
echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f /etc/ansible/facts.d/local_facts.fact ]; then
|
if [ ! -f /etc/ansible/facts.d/local_facts.fact ]; then
|
||||||
mkdir -p /etc/ansible/facts.d
|
mkdir -p /etc/ansible/facts.d
|
||||||
fi
|
fi
|
||||||
cp ./scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact
|
cp ./scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact
|
||||||
|
echo "Placed /etc/ansible/facts.d/local_facts.fact into position."
|
||||||
|
|
||||||
STAGE=""
|
# Stage 0 will always be run. From there on up to Stage 9 we keep a counter
|
||||||
|
# (in /etc/iiab/iiab.env) of the highest completed Stage. Avoid repetition!
|
||||||
|
STAGE=0
|
||||||
if [ ! -f /etc/iiab/iiab.env ]; then
|
if [ ! -f /etc/iiab/iiab.env ]; then
|
||||||
mkdir -p /etc/iiab
|
mkdir -p /etc/iiab
|
||||||
# ./scripts/ansible # needs discussion
|
|
||||||
else
|
else
|
||||||
OLD=`grep XSCE /etc/iiab/iiab.env | wc -l`
|
if [[ `grep STAGE= /etc/iiab/iiab.env` ]]; then
|
||||||
if [ "$OLD" != 0 ] || [ "$1" == "--reinstall" ]; then
|
|
||||||
echo "Found old XSCE install - re-installing from scratch"
|
|
||||||
rm /etc/iiab/iiab.env
|
|
||||||
# check ansible version here and force ansible upgrade if needed
|
|
||||||
else
|
|
||||||
source /etc/iiab/iiab.env
|
source /etc/iiab/iiab.env
|
||||||
if [ "$1" == "--debug" ]; then
|
echo "Extracted STAGE="$STAGE" (counter) from /etc/iiab/iiab.env"
|
||||||
echo "Entering debug mode"
|
if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then
|
||||||
sed -i -e 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env
|
echo -e "\nEXITING: STAGE (counter) value == "$STAGE" is non-integer in /etc/iiab/iiab.env"
|
||||||
elif [ ! $STAGE == 9 ]; then
|
exit 1
|
||||||
echo "Restarting *after* STAGE $STAGE..as soon as Stage 0 completes. Stage 9 comes last."
|
elif [ "$STAGE" -lt 1 ] || [ "$STAGE" -gt 9 ]; then
|
||||||
elif [ $STAGE == 9 ]; then
|
echo -e "\nEXITING: STAGE (counter) value == "$STAGE" is out-of-range in /etc/iiab/iiab.env"
|
||||||
# place keeper add read response
|
|
||||||
# "offer 'Y' or stage number dialog box option to override"
|
|
||||||
echo "'iiab-install' has already been completed."
|
|
||||||
echo "Use --debug to override."
|
|
||||||
#echo "In demo mode not preventing second run"
|
|
||||||
echo "Exiting."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if [[ `grep XSCE /etc/iiab/iiab.env` ]] || [ "$1" == "--reinstall" ]; then
|
||||||
|
STAGE=0
|
||||||
|
rm /etc/iiab/iiab.env
|
||||||
|
echo "Removed /etc/iiab/iiab.env effectively resetting STAGE (counter)."
|
||||||
|
elif [ "$STAGE" -ge 2 ] && [ "$1" == "--debug" ]; then
|
||||||
|
STAGE=2
|
||||||
|
sed -i 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env
|
||||||
|
echo "Wrote STAGE=2 (counter) to /etc/iiab/iiab.env"
|
||||||
|
elif [ "$STAGE" -eq 9 ]; then
|
||||||
|
echo -e "\nEXITING: STAGE (counter) in /etc/iiab/iiab.env shows Stage 9 Is Already Done."
|
||||||
|
echo "Use './iiab-install --reinstall' to force running all Stages 0-9."
|
||||||
|
echo "Use './iiab-install --debug' to run Stage 0, followed by Stages 3-9."
|
||||||
|
echo "Use './runtags' to run a single Stage or Tag or Role."
|
||||||
|
echo "Use './iiab-network' to run Network sections."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ "$STAGE" -lt 2 ] && [ "$1" == "--debug" ]; then
|
||||||
|
echo -e "\n'--debug' *ignored* as STAGE (counter) < 2."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if vars/local_vars.yml is missing, put a default one in place - First Run
|
# If vars/local_vars.yml is missing, put a default file in place.
|
||||||
if [ ! -f ./vars/local_vars.yml ]; then
|
if [ ! -f ./vars/local_vars.yml ]; then
|
||||||
case $OS in
|
case $OS in
|
||||||
OLPC | fedora)
|
OLPC | fedora)
|
||||||
cp ./vars/olpc.localvars ./vars/local_vars.yml
|
cp ./vars/olpc.localvars ./vars/local_vars.yml
|
||||||
|
echo -e "\nvars/local_vars.yml created from olpc.localvars defaults."
|
||||||
;;
|
;;
|
||||||
centos | debian | ubuntu | raspbian)
|
centos | debian | ubuntu | raspbian)
|
||||||
cp ./vars/medium.localvars ./vars/local_vars.yml
|
cp ./vars/medium.localvars ./vars/local_vars.yml
|
||||||
|
echo -e "\nvars/local_vars.yml created from medium.localvars defaults."
|
||||||
|
echo "See MIN/MEDIUM/BIG options @ http://wiki.iiab.io/local_vars.yml"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "IIAB supports raspbian, debian, ubuntu, centos, and OLPC - exiting now..."
|
echo -e "\nEXITING: IIAB requires Raspbian, Debian, Ubuntu, CentOS or OLPC/Fedora."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Running local playbooks!"
|
echo -e "\nTRY TO RERUN './iiab-install' IF IT FAILS DUE TO CONNECTIVITY ISSUES ETC!"
|
||||||
|
echo -e "\nRunning local playbooks....Stage 0 will now run....followed by Stages $(($STAGE + 1))-9"
|
||||||
|
|
||||||
ansible -m setup -i $INVENTORY localhost --connection=local >> /dev/null
|
ansible -m setup -i $INVENTORY localhost --connection=local >> /dev/null
|
||||||
ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local
|
ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#- name: Loading computed_vars
|
#- name: Loading computed_vars
|
||||||
# include_tasks: roles/0-init/tasks/computed_vars.yml
|
# include_tasks: roles/0-init/tasks/computed_vars.yml
|
||||||
- name: re-read local_facts.facts from /etc/ansible/facts.d
|
- name: Re-read local_facts.facts from /etc/ansible/facts.d
|
||||||
setup: filter=ansible_local
|
setup: filter=ansible_local
|
||||||
|
|
||||||
# set top level variables from local facts for convenience
|
# set top level variables from local facts for convenience
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
iiab_stage: '{{ ansible_local.local_facts.stage }}'
|
iiab_stage: '{{ ansible_local.local_facts.stage }}'
|
||||||
|
|
||||||
# Networking uses a different file for the rpi
|
# Networking uses a different file for the rpi
|
||||||
- name: Discover if this is a rpi -- assume if so it is running raspbian
|
- name: Discover if this is a RPi -- if so assume it is running Raspbian
|
||||||
set_fact:
|
set_fact:
|
||||||
rpi_model: "rpi"
|
rpi_model: "rpi"
|
||||||
is_rpi: True
|
is_rpi: True
|
||||||
|
@ -116,12 +116,12 @@
|
||||||
docker_enabled: True
|
docker_enabled: True
|
||||||
when: schooltool_enabled or schooltool_install
|
when: schooltool_enabled or schooltool_install
|
||||||
|
|
||||||
- name: Set python_path for is_redhat
|
- name: Set python_path (redhat)
|
||||||
set_fact:
|
set_fact:
|
||||||
python_path: /usr/lib/python2.7/site-packages/
|
python_path: /usr/lib/python2.7/site-packages/
|
||||||
when: is_redhat
|
when: is_redhat
|
||||||
|
|
||||||
- name: Set python_path for is_debuntu
|
- name: Set python_path (debuntu)
|
||||||
set_fact:
|
set_fact:
|
||||||
python_path: /usr/local/lib/python2.7/dist-packages/
|
python_path: /usr/local/lib/python2.7/dist-packages/
|
||||||
when: is_debuntu
|
when: is_debuntu
|
||||||
|
@ -134,14 +134,14 @@
|
||||||
set_fact:
|
set_fact:
|
||||||
mysql_service: mariadb
|
mysql_service: mariadb
|
||||||
|
|
||||||
- name: Set mysqld_service to mysqld for Fedora 18
|
- name: Set mysqld_service to mysqld (etc) for Fedora 18
|
||||||
set_fact:
|
set_fact:
|
||||||
mysql_service: mysqld
|
mysql_service: mysqld
|
||||||
no_NM_reload: True
|
no_NM_reload: True
|
||||||
is_F18: True
|
is_F18: True
|
||||||
when: ansible_distribution_release == "based on Fedora 18" or ansible_distribution_version == "18"
|
when: ansible_distribution_release == "based on Fedora 18" or ansible_distribution_version == "18"
|
||||||
|
|
||||||
- name: Set mysql_service to mysql for Debian
|
- name: Set mysql_service to mysql (debuntu)
|
||||||
set_fact:
|
set_fact:
|
||||||
mysql_service: mysql
|
mysql_service: mysql
|
||||||
when: is_debuntu
|
when: is_debuntu
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
FQDN_changed: True
|
FQDN_changed: True
|
||||||
when: iiab_fqdn != ansible_fqdn
|
when: iiab_fqdn != ansible_fqdn
|
||||||
|
|
||||||
- name: add version section
|
- name: Add version section
|
||||||
ini_file: dest='{{ iiab_config_file }}'
|
ini_file: dest='{{ iiab_config_file }}'
|
||||||
section=runtime
|
section=runtime
|
||||||
option='{{ item.option }}'
|
option='{{ item.option }}'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Assume we only get here if elgg_install: True
|
# Assume we only get here if elgg_install: True
|
||||||
# Assume mysql is running
|
# Assume mysql is running
|
||||||
|
|
||||||
- name: Download current version from our copy
|
- name: Download current version from our site
|
||||||
shell: wget {{ iiab_download_url }}/elgg-{{ elgg_version }}.zip -c -P {{ downloads_dir }}
|
shell: wget {{ iiab_download_url }}/elgg-{{ elgg_version }}.zip -c -P {{ downloads_dir }}
|
||||||
creates={{ downloads_dir }}/elgg-{{ elgg_version }}.zip
|
creates={{ downloads_dir }}/elgg-{{ elgg_version }}.zip
|
||||||
when: internet_available
|
when: internet_available
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
- name: Change permissions on engine directory so Apache can write
|
- name: Change permissions on engine directory so Apache can write
|
||||||
file: path=/opt/elgg/engine/ owner={{ apache_user }} mode=0755 state=directory
|
file: path=/opt/elgg/engine/ owner={{ apache_user }} mode=0755 state=directory
|
||||||
|
|
||||||
- name: Create an upload directory that Apache can write in or elgg
|
- name: Create an upload directory that Apache can write in or Elgg
|
||||||
file: path={{ elgg_upload_path }} state=directory owner={{ apache_user }}
|
file: path={{ elgg_upload_path }} state=directory owner={{ apache_user }}
|
||||||
|
|
||||||
- name: Change ownership
|
- name: Change ownership
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
# tar up a mysqldump of freshly installed database and use it in the install to avoid the startup
|
# tar up a mysqldump of freshly installed database and use it in the install to avoid the startup
|
||||||
# form, which worries me a lot. (/var/lib/mysql/elggdb)
|
# form, which worries me a lot. (/var/lib/mysql/elggdb)
|
||||||
|
|
||||||
- name: Load elgg database dump
|
- name: Load Elgg database dump
|
||||||
mysql_db: name={{ dbname }}
|
mysql_db: name={{ dbname }}
|
||||||
state=import
|
state=import
|
||||||
target=/tmp/elggdb.sql
|
target=/tmp/elggdb.sql
|
||||||
|
@ -92,26 +92,26 @@
|
||||||
- name: Remove database dump after load
|
- name: Remove database dump after load
|
||||||
file: name=/tmp/elggdb.sql state=absent
|
file: name=/tmp/elggdb.sql state=absent
|
||||||
|
|
||||||
- name: Install config file for elgg in Apache
|
- name: Install config file for Elgg in Apache
|
||||||
template: src=elgg.conf dest=/etc/{{ apache_config_dir }}/elgg.conf
|
template: src=elgg.conf dest=/etc/{{ apache_config_dir }}/elgg.conf
|
||||||
|
|
||||||
- name: Enable Elgg for debuntu (will already be enabled above for Redhat)
|
- name: Enable Elgg for debuntu (will already be enabled above for redhat)
|
||||||
file: path=/etc/apache2/sites-enabled/elgg.conf
|
file: path=/etc/apache2/sites-enabled/elgg.conf
|
||||||
src=/etc/apache2/sites-available/elgg.conf
|
src=/etc/apache2/sites-available/elgg.conf
|
||||||
state=link
|
state=link
|
||||||
when: elgg_enabled and is_debuntu
|
when: elgg_enabled and is_debuntu
|
||||||
|
|
||||||
- name: Disable Elgg for debuntu
|
- name: Disable Elgg - remove config file for Elgg in Apache (debuntu)
|
||||||
file: path=/etc/apache2/sites-enabled/elgg.conf
|
file: path=/etc/apache2/sites-enabled/elgg.conf
|
||||||
state=absent
|
state=absent
|
||||||
when: not elgg_enabled and is_debuntu
|
when: not elgg_enabled and is_debuntu
|
||||||
|
|
||||||
- name: Disable Elgg for Redhat - remove config file for Elgg in Apache
|
- name: Disable Elgg - remove config file for Elgg in Apache (redhat)
|
||||||
file: dest=/etc/{{ apache_config_dir }}/elgg.conf
|
file: dest=/etc/{{ apache_config_dir }}/elgg.conf
|
||||||
state=absent
|
state=absent
|
||||||
when: not elgg_enabled and is_redhat
|
when: not elgg_enabled and is_redhat
|
||||||
|
|
||||||
- name: Add Elgg to service list
|
- name: Add 'elgg' to service list
|
||||||
ini_file: dest='{{ service_filelist }}'
|
ini_file: dest='{{ service_filelist }}'
|
||||||
section=elgg
|
section=elgg
|
||||||
option='{{ item.option }}'
|
option='{{ item.option }}'
|
||||||
|
@ -126,5 +126,5 @@
|
||||||
- option: enabled
|
- option: enabled
|
||||||
value: "{{ elgg_enabled }}"
|
value: "{{ elgg_enabled }}"
|
||||||
|
|
||||||
- name: Restart apache, so it picks up the new aliases
|
- name: Restart Apache, so it picks up the new aliases
|
||||||
service: name={{ apache_service }} state=restarted
|
service: name={{ apache_service }} state=restarted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue