From b691bd8252a67205f6c6f4c7660fc7c18153b780 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Dec 2022 13:34:30 -0500 Subject: [PATCH 1/3] Dynamically extract python_ver & postgresql_version --- roles/0-init/tasks/main.yml | 10 ++++++---- roles/lokole/tasks/install.yml | 17 ++++++++++++----- roles/postgresql/tasks/install.yml | 11 ++++++++--- scripts/local_facts.fact | 16 +++++++++++++--- vars/debian-11.yml | 4 ++-- vars/debian-12.yml | 4 ++-- vars/linuxmint-20.yml | 4 ++-- vars/linuxmint-21.yml | 4 ++-- vars/raspbian-11.yml | 4 ++-- .../{ubuntu-2004.yml => ubuntu-2004.yml.unused} | 0 vars/ubuntu-2204.yml | 4 ++-- vars/ubuntu-2210.yml | 4 ++-- vars/ubuntu-2304.yml | 4 ++-- 13 files changed, 55 insertions(+), 31 deletions(-) rename vars/{ubuntu-2004.yml => ubuntu-2004.yml.unused} (100%) diff --git a/roles/0-init/tasks/main.yml b/roles/0-init/tasks/main.yml index a12c91156..27de31b64 100644 --- a/roles/0-init/tasks/main.yml +++ b/roles/0-init/tasks/main.yml @@ -7,12 +7,13 @@ # Higher-level purpose explained at the bottom of: # https://github.com/iiab/iiab/blob/master/vars/default_vars.yml -- name: "Ansible just ran /etc/ansible/facts.d/local_facts.fact to set 11 vars -- here we extract 3 of those -- rpi_model: {{ ansible_local.local_facts.rpi_model }}, devicetree_model: {{ ansible_local.local_facts.devicetree_model }}, iiab_stage: {{ ansible_local.local_facts.stage }}" +- name: "Ansible just ran /etc/ansible/facts.d/local_facts.fact to set 14 vars -- here we extract 5 of those -- iiab_stage: {{ ansible_local.local_facts.stage }}, rpi_model: {{ ansible_local.local_facts.rpi_model }}, devicetree_model: {{ ansible_local.local_facts.devicetree_model }}, os_ver: {{ ansible_local.local_facts.os_ver }}, python_ver: {{ ansible_local.local_facts.python_ver }}" set_fact: iiab_stage: "{{ ansible_local.local_facts.stage }}" rpi_model: "{{ ansible_local.local_facts.rpi_model }}" devicetree_model: "{{ ansible_local.local_facts.devicetree_model }}" os_ver: "{{ ansible_local.local_facts.os_ver }}" + python_ver: "{{ ansible_local.local_facts.python_ver }}" # Initialize /etc/iiab/iiab.ini writing the 'location' and 'version' sections # once and only once, to preserve the install date and git hash. @@ -21,9 +22,8 @@ when: not iiab_ini_test.stat.exists # 2021-07-30: The 'first_run' flag isn't much used anymore. In theory it's -# still used in these 2 places: -# (1) roles/1-prep/tasks/hardware.yml for raspberry_pi.yml -# (2) roles/network/tasks/named.yml for "Stop named before copying files" +# still used in 1-prep/tasks/hardware.yml for raspberry_pi.yml +# # This needs to be reworked for 0-init speed, and overall understandability. - name: Set first_run flag set_fact: @@ -96,6 +96,8 @@ value: "{{ devicetree_model }}" - option: os_ver value: "{{ os_ver }}" + - option: python_ver + value: "{{ python_ver }}" - option: first_run value: "{{ first_run }}" - option: local_tz # e.g. 'EDT' (summer) or 'EST' (winter) after Ansible interprets symlink /etc/localtime -- or 'UTC' if /etc/localtime doesn't exist diff --git a/roles/lokole/tasks/install.yml b/roles/lokole/tasks/install.yml index b472ebdd3..82b1c9cf4 100644 --- a/roles/lokole/tasks/install.yml +++ b/roles/lokole/tasks/install.yml @@ -2,10 +2,10 @@ # https://github.com/iiab/iiab/blob/master/roles/www_base/templates/iiab-refresh-wiki-docs.sh#L51-L52 -- name: "Install 8 packages for Lokole: python3, python3-pip, python3-venv, python3-dev, python3-bcrypt, libffi-dev, libssl-dev, libopenjp2-7" +- name: Install 14 packages for Lokole apt: name: - - python3 + #- python3 # 2022-12-21: IIAB pre-req, see scripts/local_facts.fact - python3-pip - python3-venv - python3-dev @@ -55,12 +55,19 @@ extra_args: --no-cache-dir # To avoid caching issues e.g. soon after new releases hit https://pypi.org/project/opwen-email-client/ when: lokole_commit is undefined and lokole_version is undefined -- name: Compile translations +# 2022-12-21: Dynamic callout to Python moved to scripts/local_facts.fact (Python 3 is now a mandatory IIAB pre-req) +# - name: Compile translations +# shell: | +# python_version=$(python3 -c 'from sys import version_info; print("%s.%s" % (version_info.major, version_info.minor));';) +# {{ lokole_venv }}/bin/pybabel compile -d {{ item }}/translations +# with_items: +# - "{{ lokole_venv }}/lib/python${python_version}/site-packages/opwen_email_client/webapp" + +- name: Compile translations for Python {{ python_ver }} shell: | - python_version=$(python3 -c 'from sys import version_info; print("%s.%s" % (version_info.major, version_info.minor));';) {{ lokole_venv }}/bin/pybabel compile -d {{ item }}/translations with_items: - - "{{ lokole_venv }}/lib/python${python_version}/site-packages/opwen_email_client/webapp" + - "{{ lokole_venv }}/lib/python{{ python_ver }}/site-packages/opwen_email_client/webapp" - name: Create system {{ lokole_user }} user ansible.builtin.user: diff --git a/roles/postgresql/tasks/install.yml b/roles/postgresql/tasks/install.yml index 3fa1a95d0..df2918a32 100644 --- a/roles/postgresql/tasks/install.yml +++ b/roles/postgresql/tasks/install.yml @@ -6,13 +6,18 @@ - python3-psycopg2 # For Ansible modules {postgresql_db, postgresql_user} in Ansible collection community.postgresql -- used in moodle/tasks/install.yml state: present +- name: Run shell command "pg_config --version" to extract MAJOR version numner -- strip off MINOR/PATCH version number(s) + shell: pg_config --version | sed 's/^[^0-9]*//' | sed 's/[^0-9].*//' + register: pg_config_version + +- name: 'Dynamically set Ansible var "postgresql_version: {{ pg_config_version.stdout }}"' + set_fact: + postgresql_version: "{{ pg_config_version.stdout }}" + - name: Install /etc/systemd/system/postgresql-iiab.service from template (0644 by default) template: src: postgresql-iiab.service dest: /etc/systemd/system/postgresql-iiab.service - # owner: root - # group: root - # mode: '0644' - name: Create PostgreSQL data dir /library/pgsql-iiab, owned by postgres:postgres (0700) file: diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index ce796fcc3..236e08619 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -11,7 +11,9 @@ STAGE=0 OS="none" -VERSION_ID="none" # This var's combined with the above, before being output +VERSION_ID="none" # Temp var, for: OS_VER="$OS-$VERSION_ID" +OS_VER="none" +PYTHON_VER="none" IIAB_REMOTE_URL="none" IIAB_BRANCH="none" IIAB_COMMIT="none" @@ -63,6 +65,7 @@ OS_VER="$OS-$VERSION_ID" #"ubuntu-17" | \ #"ubuntu-18" | \ #"ubuntu-19" | \ + #"ubuntu-2004" | \ #"ubuntu-2104" | \ #"ubuntu-2110" | \ #"centos-7" | \ @@ -76,7 +79,6 @@ OS_VER="$OS-$VERSION_ID" case $OS_VER in "debian-11" | \ "debian-12" | \ - "ubuntu-2004" | \ "ubuntu-2204" | \ "ubuntu-2210" | \ "ubuntu-2304" | \ @@ -123,6 +125,13 @@ tmp=$(ansible --version) && #ANSIBLE_VERSION=$(echo "$tmp" | head -1 | awk '{print $2}') #ANSIBLE_VERSION=$(echo "$tmp" | head -1 | sed -e 's/.* //') +if tmp=$(python3 -c 'from sys import version_info; print("%s.%s" % (version_info.major, version_info.minor));'); then + PYTHON_VER=$tmp +else + echo -e "\e[1m\nPython 3 is REQUIRED for Internet-in-a-Box. You might want to run:\n\nsudo apt install python3\n\e[0m" + exit 1 +fi + # THE LAST 3 BELOW ARE DIFFERENT as "systemctl is-enabled" unhelpfully returns # the same error code (i.e. 1) REGARDLESS whether the service is (A) disabled @@ -159,5 +168,6 @@ cat < Date: Wed, 21 Dec 2022 14:07:10 -0500 Subject: [PATCH 2/3] postgresql/tasks/install.yml typo: numner -> number --- roles/postgresql/tasks/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/postgresql/tasks/install.yml b/roles/postgresql/tasks/install.yml index df2918a32..dd7ac22b3 100644 --- a/roles/postgresql/tasks/install.yml +++ b/roles/postgresql/tasks/install.yml @@ -6,7 +6,7 @@ - python3-psycopg2 # For Ansible modules {postgresql_db, postgresql_user} in Ansible collection community.postgresql -- used in moodle/tasks/install.yml state: present -- name: Run shell command "pg_config --version" to extract MAJOR version numner -- strip off MINOR/PATCH version number(s) +- name: Run shell command "pg_config --version" to extract MAJOR version number -- strip off MINOR/PATCH version number(s) shell: pg_config --version | sed 's/^[^0-9]*//' | sed 's/[^0-9].*//' register: pg_config_version From b8e0b5e13a398188b9ed3c899c570f34c6d4614c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Dec 2022 14:18:27 -0500 Subject: [PATCH 3/3] Cleaner sed in nextcloud, postgresql, iiab-diagnostics --- roles/nextcloud/tasks/install.yml | 2 +- roles/postgresql/tasks/install.yml | 2 +- scripts/iiab-diagnostics | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/roles/nextcloud/tasks/install.yml b/roles/nextcloud/tasks/install.yml index 0d5dafea4..1d6e135cc 100644 --- a/roles/nextcloud/tasks/install.yml +++ b/roles/nextcloud/tasks/install.yml @@ -3,7 +3,7 @@ # - name: Try to run 'php -v' to get PHP version # # e.g. converts multi-line "PHP 7.0.33-0ubuntu0.16.04.5 (cli) ( NTS ) ..." to "7.0.33" -# shell: php -v | head -1 | sed 's/^[^0-9.]*//' | sed 's/[^0-9.].*//' +# shell: php -v | head -1 | sed 's/^[^0-9.]*//; s/[^0-9.].*//' # register: php_version_installed # #ignore_errors: yes # NOT NEC: if php is not installed, php_version_installed.stdout will get set to "" diff --git a/roles/postgresql/tasks/install.yml b/roles/postgresql/tasks/install.yml index dd7ac22b3..6c7cdb4fc 100644 --- a/roles/postgresql/tasks/install.yml +++ b/roles/postgresql/tasks/install.yml @@ -7,7 +7,7 @@ state: present - name: Run shell command "pg_config --version" to extract MAJOR version number -- strip off MINOR/PATCH version number(s) - shell: pg_config --version | sed 's/^[^0-9]*//' | sed 's/[^0-9].*//' + shell: pg_config --version | sed 's/^[^0-9]*//; s/[^0-9].*//' register: pg_config_version - name: 'Dynamically set Ansible var "postgresql_version: {{ pg_config_version.stdout }}"' diff --git a/scripts/iiab-diagnostics b/scripts/iiab-diagnostics index ed243490c..7361e5621 100755 --- a/scripts/iiab-diagnostics +++ b/scripts/iiab-diagnostics @@ -8,18 +8,18 @@ IIAB_RELEASE=$(cat /etc/iiab/iiab.env | grep IIAB_RELEASE | cut -d'=' -f2) OS_VER=$(cat /etc/iiab/iiab.env | grep OS_VER | cut -d'=' -f2) YMDT=$(date +%F_%T_%Z) -git config --global --add safe.directory /opt/iiab/iiab # Nec below, if non-root -HASH1=$(cd /opt/iiab/iiab; git log --pretty=format:'%H' -n 1) # --pretty=format:'%h' (8 chars) -BRANCH1=$(cd /opt/iiab/iiab; git branch --show-current) -REMOTE_URL1=$(cd /opt/iiab/iiab; git config remote.$(git config branch.$BRANCH1.remote).url) -PR_COUNT1=$(cd /opt/iiab/iiab; git log "$(git describe --tags --abbrev=0)..HEAD" --oneline --grep='Merge pull request' | wc -l) -TAG_COMMITS1=$(cd /opt/iiab/iiab; git describe --tags | sed 's/-[^-]*$//' | sed 's/-\([[:digit:]][[:digit:]]*\)$/ (\1 commits)/') -git config --global --add safe.directory /opt/iiab/iiab-admin-console # Nec below, if non-root -HASH2=$(cd /opt/iiab/iiab-admin-console; git log --pretty=format:'%H' -n 1) -BRANCH2=$(cd /opt/iiab/iiab-admin-console; git branch --show-current) -REMOTE_URL2=$(cd /opt/iiab/iiab-admin-console; git config remote.$(git config branch.$BRANCH2.remote).url) -PR_COUNT2=$(cd /opt/iiab/iiab-admin-console; git log "$(git describe --tags --abbrev=0)..HEAD" --oneline --grep='Merge pull request' | wc -l) -TAG_COMMITS2=$(cd /opt/iiab/iiab-admin-console; git describe --tags | sed 's/-[^-]*$//' | sed 's/-\([[:digit:]][[:digit:]]*\)$/ (\1 commits)/') +# git config --global --add safe.directory /opt/iiab/iiab # Nec below, if non-root +# HASH1=$(cd /opt/iiab/iiab; git log --pretty=format:'%H' -n 1) # --pretty=format:'%h' (8 chars) +# BRANCH1=$(cd /opt/iiab/iiab; git branch --show-current) +# REMOTE_URL1=$(cd /opt/iiab/iiab; git config remote.$(git config branch.$BRANCH1.remote).url) +# PR_COUNT1=$(cd /opt/iiab/iiab; git log "$(git describe --tags --abbrev=0)..HEAD" --oneline --grep='Merge pull request' | wc -l) +# TAG_COMMITS1=$(cd /opt/iiab/iiab; git describe --tags | sed 's/-[^-]*$//; s/-\([[:digit:]][[:digit:]]*\)$/ (\1 commits)/') +# git config --global --add safe.directory /opt/iiab/iiab-admin-console # Nec below, if non-root +# HASH2=$(cd /opt/iiab/iiab-admin-console; git log --pretty=format:'%H' -n 1) +# BRANCH2=$(cd /opt/iiab/iiab-admin-console; git branch --show-current) +# REMOTE_URL2=$(cd /opt/iiab/iiab-admin-console; git config remote.$(git config branch.$BRANCH2.remote).url) +# PR_COUNT2=$(cd /opt/iiab/iiab-admin-console; git log "$(git describe --tags --abbrev=0)..HEAD" --oneline --grep='Merge pull request' | wc -l) +# TAG_COMMITS2=$(cd /opt/iiab/iiab-admin-console; git describe --tags | sed 's/-[^-]*$//; s/-\([[:digit:]][[:digit:]]*\)$/ (\1 commits)/') echo -e "\nGathers IIAB diagnostics into 1 file, to accelerate troubleshooting. USAGE:" echo