From 429aa04ce5ea3341a84a55372472557035e42e42 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 17 Sep 2020 09:15:55 -0500 Subject: [PATCH] Infastructure for proper versioning. (#2500) * each major role change can be recorded in upgrade_roles with a bump in iiab_revision to denote the addition * test source for https://github.com/iiab/iiab-factory/pull/134 * keep iiab_revision with role name * gitea * introduce $INSTALLED_RELEASE $INSTALLED_REVISION into ansible * set informational 'do_facts' * 7.1.5-premap tag as starting point for iiab_revision 0 * no notes at all - use underscore for role name to match what is in iiab_state.yml * use installed_revision trigger do_upgrade do_reinstall will denote a major upgrade path in the future --- roles/0-init/defaults/main.yml | 2 ++ roles/0-init/tasks/main.yml | 47 ++++++++++++++++++++--------- roles/9-local-addons/tasks/main.yml | 6 ++++ scripts/local_facts.fact | 6 ++++ upgrade_roles | 3 ++ upgrade_roles.txt | 11 +++++++ vars/default_vars.yml | 2 +- 7 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 upgrade_roles create mode 100644 upgrade_roles.txt diff --git a/roles/0-init/defaults/main.yml b/roles/0-init/defaults/main.yml index 4a9b1e4c1..fe0bb4dcf 100644 --- a/roles/0-init/defaults/main.yml +++ b/roles/0-init/defaults/main.yml @@ -8,6 +8,8 @@ first_run: False rpi_model: none xo_model: none +do_upgrade: False +do_reinstall: False gw_active: False internet_available: False discovered_wan_iface: none diff --git a/roles/0-init/tasks/main.yml b/roles/0-init/tasks/main.yml index 7b4fa58c4..5915b936a 100644 --- a/roles/0-init/tasks/main.yml +++ b/roles/0-init/tasks/main.yml @@ -1,20 +1,21 @@ # Initialize - name: ...IS BEGINNING ============================================ - stat: - path: "{{ iiab_env_file }}" - register: NewInstall - -- name: Set first_run flag - set_fact: - first_run: True - when: not NewInstall.stat.exists - -- name: Set top-level variables from local_facts for convenience +#- name: Re-read local_facts.facts from /etc/ansible/facts.d +# setup: +# filter: ansible_local +#- name: Set top-level variables from local_facts for convenience set_fact: rpi_model: "{{ ansible_local.local_facts.rpi_model }}" xo_model: "{{ ansible_local.local_facts.xo_model }}" phplib_dir: "{{ ansible_local.local_facts.phplib_dir }}" iiab_stage: "{{ ansible_local.local_facts.stage }}" + installed_release: "{{ ansible_local.local_facts.installed_release }}" + installed_revision: "{{ ansible_local.local_facts.installed_revision }}" + +- name: Set first_run flag + set_fact: + first_run: True + when: iiab_stage | int == 0 # We need to inialize the ini file and only write the location and version # sections once and only once to preserve the install date and git hash. @@ -36,13 +37,31 @@ path: /etc/iiab/diag mode: '0777' -- name: Re-read local_facts.facts from /etc/ansible/facts.d - setup: - filter: ansible_local - - name: Pre-check that IIAB's "XYZ_install" + "XYZ_enabled" vars (1) are defined, (2) are boolean-not-string variables, and (3) contain plausible values. Also checks that "XYZ_install" is True when "XYZ_installed" is defined. include_tasks: validate_vars.yml +# the below 2 stanza don't do anything functional at the moment, more +# informational you will see 'changed'. The real work would be done by +# iiab-upgrade via auto deleting the *_installed flag in iiab_state.yml +# based on entries in upgrade_roles. It is just plain easier to delete the +# marker before ansible loads iiab_state.yml like runrole --reinstall does. +# https://github.com/jvonau/iiab-factory/blob/iiab-upgrade/iiab-upgrade +# Might work on loading iiab_state.yml on demand via conditionals in the future. + +# this one is informational you will see 'changed'. +- name: Upgrade situation detected + set_fact: + do_upgrade: True + when: installed_revision|int < iiab_revision|int + +# leave at 7.2 when branching to 7.3, bump to 7.3 when 7.4 or 8.0 comes along. +# does nothing at the moment for future use, just denotes a major change in the +# starting point of the install. +- name: Reinstall situation detected + set_fact: + do_reinstall: True + when: not installed_release == "0" and installed_release == "7.2" + # Discover: do we have a gateway? # If Ansible detects gateway, becomes WAN candidate. - name: "Do we have a gateway? If so set discovered_wan_iface: {{ ansible_default_ipv4.alias }}" diff --git a/roles/9-local-addons/tasks/main.yml b/roles/9-local-addons/tasks/main.yml index a3d75b443..7427cc37b 100644 --- a/roles/9-local-addons/tasks/main.yml +++ b/roles/9-local-addons/tasks/main.yml @@ -30,6 +30,12 @@ name: calibre-web when: calibreweb_install | bool +- name: Record IIAB_REVISION + lineinfile: + path: "{{ iiab_env_file }}" + regexp: '^IIAB_REVISION=*' + line: 'IIAB_REVISION={{ iiab_revision }}' + - name: Recording STAGE 9 HAS COMPLETED ==================== lineinfile: path: "{{ iiab_env_file }}" diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index 35b409493..68f59f5c8 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -5,8 +5,12 @@ if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env STAGE=$STAGE + INSTALLED_RELEASE=$IIAB_RELEASE + INSTALLED_REVISION=$IIAB_REVISION else STAGE=0 + INSTALLED_RELEASE=0 + INSTALLED_REVISION=0 fi OS=`grep ^ID= /etc/*elease|cut -d= -f2` @@ -84,6 +88,8 @@ SYSD_NETD=`systemctl is-enabled systemd-networkd` cat <