From c533cf7e77bbdfbb9258a558ff750ee80e36cec9 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 19 Oct 2020 03:01:57 -0700 Subject: [PATCH 1/6] Update local_facts.fact --- scripts/local_facts.fact | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index 35b409493..70c14713d 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -4,12 +4,12 @@ # interruptions return last stage number recorded (1-9) if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env - STAGE=$STAGE + STAGE=$STAGE # What does this line do? else STAGE=0 fi -OS=`grep ^ID= /etc/*elease|cut -d= -f2` +OS=`grep ^ID= /etc/*elease | cut -d= -f2` OS=${OS//\"/} if [ -f /etc/rpi-issue ]; then OS="raspbian" @@ -50,12 +50,10 @@ COMMIT=`git rev-parse --verify HEAD` if [ -d /usr/lib64/php ]; then PHPLIB_DIR=/usr/lib64/php +elif [ -d /usr/lib/php5 ]; then + PHPLIB_DIR=/usr/lib/php5 else - if [ -d /usr/lib/php5 ]; then - PHPLIB_DIR=/usr/lib/php5 - else - PHPLIB_DIR=/usr/lib/php - fi + PHPLIB_DIR=/usr/lib/php fi if [ -f /proc/device-tree/mfg-data/MN ]; then @@ -70,14 +68,14 @@ else RPI_VERSION="none" fi -ANSIBLE_VERSION=$(ansible --version|head -n 1|cut -f 2 -d " ") +ANSIBLE_VERSION=$(ansible --version | head -n 1 | cut -f 2 -d " ") -if [ ! x$DHCPCD_PATH = x ]; then +if [[ $DHCPCD_PATH != "" ]]; then DHCPCD=`systemctl is-enabled dhcpcd` fi # the check is debian family only is_redhat would use NetworkManager as the # service name. -if [ ! x$NM_PATH = x ]; then +if [[ $NM_PATH != "" ]]; then NM=`systemctl is-enabled network-manager` fi SYSD_NETD=`systemctl is-enabled systemd-networkd` From 92a09a5d736bf101bccc81e92feecdba967abb91 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 19 Oct 2020 03:25:39 -0700 Subject: [PATCH 2/6] Update local_facts.fact --- scripts/local_facts.fact | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index 70c14713d..82890a2a6 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -4,7 +4,7 @@ # interruptions return last stage number recorded (1-9) if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env - STAGE=$STAGE # What does this line do? + STAGE=$STAGE # What does this line do, if anything? else STAGE=0 fi From d8f277c59e45c5a7524afb39ed77666d71b4210d Mon Sep 17 00:00:00 2001 From: root Date: Mon, 19 Oct 2020 12:45:36 -0400 Subject: [PATCH 3/6] local_facts.fact safety/readability + remove tags from .yml's --- iiab-from-cmdline.yml | 14 +++---- iiab-from-console.yml | 16 ++++---- iiab-network.yml | 4 +- iiab-stages.yml | 11 ------ install-support.yml | 8 ++-- run-one-role.yml | 4 +- scripts/local_facts.fact | 82 ++++++++++++++++++++-------------------- 7 files changed, 65 insertions(+), 74 deletions(-) diff --git a/iiab-from-cmdline.yml b/iiab-from-cmdline.yml index 2dd4e0689..74b507b56 100644 --- a/iiab-from-cmdline.yml +++ b/iiab-from-cmdline.yml @@ -9,10 +9,10 @@ - /etc/iiab/iiab_state.yml roles: - - { role: 0-init, tags: ['0-init'] } - - { role: 4-server-options, tags: ['4-server-options'] } - - { role: 5-xo-services, tags: ['5-xo-services'] } - - { role: 6-generic-apps, tags: ['6-generic-apps'] } - - { role: 7-edu-apps, tags: ['7-edu-apps'] } - - { role: 8-mgmt-tools, tags: ['8-mgmt-tools'] } - - { role: 9-local-addons, tags: ['9-local-addons'] } + - { role: 0-init } + - { role: 4-server-options } + - { role: 5-xo-services } + - { role: 6-generic-apps } + - { role: 7-edu-apps } + - { role: 8-mgmt-tools } + - { role: 9-local-addons } diff --git a/iiab-from-console.yml b/iiab-from-console.yml index 2790a34cf..e83aefdb9 100644 --- a/iiab-from-console.yml +++ b/iiab-from-console.yml @@ -9,11 +9,11 @@ - /etc/iiab/iiab_state.yml roles: - - { role: 0-init, tags: ['0-init'] } - - { role: 4-server-options, tags: ['4-server-options'] } - - { role: 5-xo-services, tags: ['5-xo-services'] } - - { role: 6-generic-apps, tags: ['6-generic-apps'] } - - { role: 7-edu-apps, tags: ['7-edu-apps'] } - - { role: 8-mgmt-tools, tags: ['8-mgmt-tools'] } - - { role: 9-local-addons, tags: ['9-local-addons'] } - - { role: network, tags: ['network'] } + - { role: 0-init } + - { role: 4-server-options } + - { role: 5-xo-services } + - { role: 6-generic-apps } + - { role: 7-edu-apps } + - { role: 8-mgmt-tools } + - { role: 9-local-addons } + - { role: network } diff --git a/iiab-network.yml b/iiab-network.yml index 13a490ed0..a72678367 100644 --- a/iiab-network.yml +++ b/iiab-network.yml @@ -9,5 +9,5 @@ - /etc/iiab/iiab_state.yml roles: - - { role: 0-init, tags: ['network'] } - - { role: network, tags: ['network','base'] } + - { role: 0-init } + - { role: network } diff --git a/iiab-stages.yml b/iiab-stages.yml index 0c1aef6f0..4b0940db6 100644 --- a/iiab-stages.yml +++ b/iiab-stages.yml @@ -14,63 +14,52 @@ - name: 0-init include_role: name: 0-init - tags: 0-init - name: 1-prep include_role: name: 1-prep when: ansible_local.local_facts.stage|int < 1 - tags: 1-prep, platform, base - name: 2-common include_role: name: 2-common when: ansible_local.local_facts.stage|int < 2 - tags: 2-common, base - name: 3-base-server include_role: name: 3-base-server when: ansible_local.local_facts.stage|int < 3 - tags: 3-base-server, base - name: 4-server-options include_role: name: 4-server-options when: ansible_local.local_facts.stage|int < 4 - tags: 4-server-options - name: 5-xo-services include_role: name: 5-xo-services when: ansible_local.local_facts.stage|int < 5 - tags: 5-xo-services - name: 6-generic-apps include_role: name: 6-generic-apps when: ansible_local.local_facts.stage|int < 6 - tags: 6-generic-apps - name: 7-edu-apps include_role: name: 7-edu-apps when: ansible_local.local_facts.stage|int < 7 - tags: 7-edu-apps - name: 8-mgmt-tools include_role: name: 8-mgmt-tools when: ansible_local.local_facts.stage|int < 8 - tags: 8-mgmt-tools - name: 9-local-addons include_role: name: 9-local-addons when: ansible_local.local_facts.stage|int < 9 - tags: 9-local-addons - name: Network include_role: name: network - tags: network diff --git a/install-support.yml b/install-support.yml index e47229004..0a6dafe33 100644 --- a/install-support.yml +++ b/install-support.yml @@ -7,7 +7,7 @@ - /etc/iiab/local_vars.yml roles: - - { role: 0-init, tags: ['0-init'] } - - { role: sshd, tags: ['sshd'] } - - { role: iiab-admin, tags: ['iiab-admin'] } - - { role: openvpn, tags: ['openvpn'] } + - { role: 0-init } + - { role: sshd } + - { role: iiab-admin } + - { role: openvpn } diff --git a/run-one-role.yml b/run-one-role.yml index 38a0b97b7..bd126eef5 100644 --- a/run-one-role.yml +++ b/run-one-role.yml @@ -9,5 +9,5 @@ - /etc/iiab/iiab_state.yml roles: - - { role: 0-init, tags: ['0-init'] } - - { role: "{{ role_to_run }}", tags: ['run'] } + - { role: 0-init } + - { role: "{{ role_to_run }}" } diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index 82890a2a6..b4b4af9fa 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -1,25 +1,28 @@ #!/bin/bash -# upgrades return found, clean installs return 0 -# interruptions return last stage number recorded (1-9) -if [ -f /etc/iiab/iiab.env ]; then - source /etc/iiab/iiab.env - STAGE=$STAGE # What does this line do, if anything? -else - STAGE=0 -fi +# 2020-10-19: Displays all errors on purpose, and uses '|| true' to continue. -OS=`grep ^ID= /etc/*elease | cut -d= -f2` -OS=${OS//\"/} +# STAGE is for ./iiab-install which runs Ansible with iiab-stages.yml +# - fresh installs start at STAGE 0 +# - interrupted installs record the last completed STAGE (1-9) +# +# We initialize to '0' (zero) to cover both situations: (1) where iiab.env does +# not exist and (2) where iiab.env exists but fails to set STAGE= +# (source command below tries to use this file, to the STAGE variable) +STAGE=0 +source /etc/iiab/iiab.env || true + +OS="none" +OS=$(grep ^ID= /etc/*elease | cut -d= -f2) || true +OS=${OS//\"/} # Remove all '"' if [ -f /etc/rpi-issue ]; then OS="raspbian" fi -VERSION_ID=`grep VERSION_ID /etc/*elease | cut -d= -f2` -VERSION_ID=${VERSION_ID//\"/} -VERSION_ID=${VERSION_ID%%.*} +VERSION_ID="none" +VERSION_ID=$(grep ^VERSION_ID= /etc/*elease | cut -d= -f2) || true +VERSION_ID=${VERSION_ID//\"/} # Remove all '"' +VERSION_ID=${VERSION_ID%%.*} # Remove all '.' and stuff to the right of 'em OS_VER=$OS-$VERSION_ID -DHCPCD_PATH=`which dhcpcd` -NM_PATH=`which NetworkManager` # Previously supported Linux distributions / versions: #"fedora-18" | \ @@ -44,41 +47,41 @@ case $OS_VER in ;; esac -# get current version -BRANCH=`git rev-parse --abbrev-ref HEAD` -COMMIT=`git rev-parse --verify HEAD` +# Get git branch and commit, indicating IIAB version +BRANCH="none" +BRANCH=$(git rev-parse --abbrev-ref HEAD) || true +COMMIT="none" +COMMIT=$(git rev-parse --verify HEAD) || true + +PHPLIB_DIR="none" if [ -d /usr/lib64/php ]; then PHPLIB_DIR=/usr/lib64/php elif [ -d /usr/lib/php5 ]; then PHPLIB_DIR=/usr/lib/php5 -else +elif [ -d /usr/lib/php ]; then PHPLIB_DIR=/usr/lib/php fi -if [ -f /proc/device-tree/mfg-data/MN ]; then - XO_VERSION=`cat /proc/device-tree/mfg-data/MN` -else - XO_VERSION="none" -fi +XO_VERSION="none" +XO_VERSION=$(cat /proc/device-tree/mfg-data/MN) || true -if [ -f /proc/device-tree/model ]; then - RPI_VERSION=`cat /proc/device-tree/model` -else - RPI_VERSION="none" -fi +RPI_VERSION="none" +RPI_VERSION=$(cat /proc/device-tree/model) || true -ANSIBLE_VERSION=$(ansible --version | head -n 1 | cut -f 2 -d " ") +ANSIBLE_VERSION="none" +ANSIBLE_VERSION=$(ansible --version | head -n 1 | cut -f 2 -d " ") || true -if [[ $DHCPCD_PATH != "" ]]; then - DHCPCD=`systemctl is-enabled dhcpcd` -fi -# the check is debian family only is_redhat would use NetworkManager as the -# service name. -if [[ $NM_PATH != "" ]]; then - NM=`systemctl is-enabled network-manager` -fi -SYSD_NETD=`systemctl is-enabled systemd-networkd` +DHCPCD="none" +DHCPCD=$(systemctl is-enabled dhcpcd) || true + +# This check is Debian family only. +# is_redhat would use NetworkManager as the service name. +NM="none" +NM=$(systemctl is-enabled network-manager) || true + +SYSD_NETD="none" +SYSD_NETD=$(systemctl is-enabled systemd-networkd) || true cat < Date: Mon, 19 Oct 2020 15:10:27 -0400 Subject: [PATCH 4/6] scripts/local_facts.fact fixed & cleaned --- scripts/local_facts.fact | 101 ++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index b4b4af9fa..cb342cce2 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -1,27 +1,47 @@ #!/bin/bash -# 2020-10-19: Displays all errors on purpose, and uses '|| true' to continue. +# 2020-10-19: Most of the 12 variables require a command[*] to be run to +# establish the var's value. WE DISPLAY ALL ERRORS / DIAGNOSTICS AND CONTINUE. +# +# [*] DOESN'T MATTER WHAT COMMAND: so long as it fails with Return Code != 0 +# If statements then use that RC to force the var to these default values... + +STAGE=0 +OS="none" +VERSION_ID="none" # This var's combined with the above, before being output +IIAB_BRANCH="none" +IIAB_COMMIT="none" +PHPLIB_DIR="none" +XO_MODEL="none" +RPI_MODEL="none" +ANSIBLE_VERSION="none" +DHCPCD="none" # The last 3 conditioned on string output not RC. SEE BELOW. +NETWORK_MANAGER="none" +SYSTEMD_NETWORKD="none" + # STAGE is for ./iiab-install which runs Ansible with iiab-stages.yml # - fresh installs start at STAGE 0 # - interrupted installs record the last completed STAGE (1-9) # -# We initialize to '0' (zero) to cover both situations: (1) where iiab.env does -# not exist and (2) where iiab.env exists but fails to set STAGE= -# (source command below tries to use this file, to the STAGE variable) -STAGE=0 -source /etc/iiab/iiab.env || true +# We initialize it to '0' (zero) to cover both situations: (1) iiab.env doesn't +# exist and (2) iiab.env exists but fails to set STAGE= (source +# command below tries to use the file...to set the STAGE variable). +source /etc/iiab/iiab.env || true # Var auto-populated so no if required! -OS="none" -OS=$(grep ^ID= /etc/*elease | cut -d= -f2) || true -OS=${OS//\"/} # Remove all '"' +if tmp=$(grep ^ID= /etc/*elease); then + OS=$(echo $tmp | cut -d= -f2) + OS=${OS//\"/} # Remove all '"' +fi if [ -f /etc/rpi-issue ]; then OS="raspbian" fi -VERSION_ID="none" -VERSION_ID=$(grep ^VERSION_ID= /etc/*elease | cut -d= -f2) || true -VERSION_ID=${VERSION_ID//\"/} # Remove all '"' -VERSION_ID=${VERSION_ID%%.*} # Remove all '.' and stuff to the right of 'em + +if tmp=$(grep ^VERSION_ID= /etc/*elease); then + VERSION_ID=$(echo $tmp | cut -d= -f2) + VERSION_ID=${VERSION_ID//\"/} # Remove all '"' + VERSION_ID=${VERSION_ID%%.*} # Remove all '.' & stuff to the right of em +fi OS_VER=$OS-$VERSION_ID # Previously supported Linux distributions / versions: @@ -47,14 +67,13 @@ case $OS_VER in ;; esac -# Get git branch and commit, indicating IIAB version -BRANCH="none" -BRANCH=$(git rev-parse --abbrev-ref HEAD) || true +# These next 2 help indicate what version of IIAB +tmp=$(git rev-parse --abbrev-ref HEAD) && + IIAB_BRANCH=$tmp -COMMIT="none" -COMMIT=$(git rev-parse --verify HEAD) || true +tmp=$(git rev-parse --verify HEAD) && + IIAB_COMMIT=$tmp -PHPLIB_DIR="none" if [ -d /usr/lib64/php ]; then PHPLIB_DIR=/usr/lib64/php elif [ -d /usr/lib/php5 ]; then @@ -63,36 +82,40 @@ elif [ -d /usr/lib/php ]; then PHPLIB_DIR=/usr/lib/php fi -XO_VERSION="none" -XO_VERSION=$(cat /proc/device-tree/mfg-data/MN) || true +tmp=$(cat /proc/device-tree/mfg-data/MN) && + XO_MODEL=$tmp -RPI_VERSION="none" -RPI_VERSION=$(cat /proc/device-tree/model) || true +tmp=$(cat /proc/device-tree/model) && + RPI_MODEL=$tmp -ANSIBLE_VERSION="none" -ANSIBLE_VERSION=$(ansible --version | head -n 1 | cut -f 2 -d " ") || true +tmp=$(ansible --version) && + ANSIBLE_VERSION=$(echo $tmp | head -n 1 | cut -f 2 -d " ") -DHCPCD="none" -DHCPCD=$(systemctl is-enabled dhcpcd) || true +# THESE LAST 3 ARE DIFFEENT as "systemctl is-enabled" unhelpfully returns the +# same rerror code (i.e. 1) REGARDLESS whether service is (A) disabled or +# (B) doesn't exist. SO WE TEST THE STRING OUTPUT INSTEAD OF THE RETURN CODE. -# This check is Debian family only. -# is_redhat would use NetworkManager as the service name. -NM="none" -NM=$(systemctl is-enabled network-manager) || true +tmp=$(systemctl is-enabled dhcpcd) +[[ $tmp = "" ]] || DHCPCD=$tmp + +# Debian family only, as is_redhat would use NetworkManager as the service name +tmp=$(systemctl is-enabled network-manager) +[[ $tmp = "" ]] || NETWORK_MANAGER=$tmp + +tmp=$(systemctl is-enabled systemd-networkd) +[[ $tmp = "" ]] || SYSTEMD_NETWORKD=$tmp -SYSD_NETD="none" -SYSD_NETD=$(systemctl is-enabled systemd-networkd) || true cat < Date: Mon, 19 Oct 2020 15:29:46 -0400 Subject: [PATCH 5/6] Clarify scripts/local_facts.fact --- scripts/local_facts.fact | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index cb342cce2..6299ab803 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -91,19 +91,24 @@ tmp=$(cat /proc/device-tree/model) && tmp=$(ansible --version) && ANSIBLE_VERSION=$(echo $tmp | head -n 1 | cut -f 2 -d " ") + # THESE LAST 3 ARE DIFFEENT as "systemctl is-enabled" unhelpfully returns the # same rerror code (i.e. 1) REGARDLESS whether service is (A) disabled or # (B) doesn't exist. SO WE TEST THE STRING OUTPUT INSTEAD OF THE RETURN CODE. tmp=$(systemctl is-enabled dhcpcd) -[[ $tmp = "" ]] || DHCPCD=$tmp +[[ $tmp != "" ]] && + DHCPCD=$tmp +#[[ $tmp ]] && DHCPCD=$tmp # Short Ain't Sweet (less understandable) # Debian family only, as is_redhat would use NetworkManager as the service name tmp=$(systemctl is-enabled network-manager) -[[ $tmp = "" ]] || NETWORK_MANAGER=$tmp +[[ $tmp != "" ]] && + NETWORK_MANAGER=$tmp tmp=$(systemctl is-enabled systemd-networkd) -[[ $tmp = "" ]] || SYSTEMD_NETWORKD=$tmp +[[ $tmp != "" ]] && + SYSTEMD_NETWORKD=$tmp cat < Date: Mon, 19 Oct 2020 15:49:43 -0400 Subject: [PATCH 6/6] scripts/local_facts.fact: Clarify STAGE var --- scripts/local_facts.fact | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index 6299ab803..22b47fcb1 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -20,14 +20,13 @@ NETWORK_MANAGER="none" SYSTEMD_NETWORKD="none" -# STAGE is for ./iiab-install which runs Ansible with iiab-stages.yml +# STAGE variable is for ./iiab-install which runs Ansible with iiab-stages.yml # - fresh installs start at STAGE 0 # - interrupted installs record the last completed STAGE (1-9) # -# We initialize it to '0' (zero) to cover both situations: (1) iiab.env doesn't -# exist and (2) iiab.env exists but fails to set STAGE= (source -# command below tries to use the file...to set the STAGE variable). -source /etc/iiab/iiab.env || true # Var auto-populated so no if required! +# We initialize it to '0' (zero) to cover the following 2 possibs: (1) iiab.env +# doesn't exist, or (2) iiab.env exists but fails to set STAGE= +source /etc/iiab/iiab.env || true # STAGE var auto-set, so no "if" required. if tmp=$(grep ^ID= /etc/*elease); then OS=$(echo $tmp | cut -d= -f2)