From 791ae23361d260465439f7d1e24431fabc9e8136 Mon Sep 17 00:00:00 2001 From: L3D Date: Mon, 22 Mar 2021 02:22:22 +0100 Subject: [PATCH] add optional versionscheck a simple version check that can prevent you from accidentally running an older version of this role. --- README.md | 1 + defaults/main.yml | 1 + tasks/main.yml | 4 ++++ tasks/versioncheck.yml | 46 ++++++++++++++++++++++++++++++++++++++++++ vars/main.yml | 3 +++ 5 files changed, 55 insertions(+) create mode 100644 tasks/versioncheck.yml diff --git a/README.md b/README.md index 881da62..f65b1b6 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Here is a deeper insight into the variables of this gitea role. For the exact fu | `gitea_gpg_server` | `hkp://keyserver.ubuntu.com:80` | A gpg key server where this role can download the gpg key | | `gitea_backup_on_upgrade` | `false` | Optionally a backup can be created with every update of gitea. | | `gitea_backup_location` | `{{ gitea_home }}/backups/` | Where to store the gitea backup if one is created with this role. | +| `submodules_versioncheck` | `false` | a simple version check that can prevent you from accidentally running an older version of this role. *(recomended)* | ### gitea in the linux world | variable name | default value | description | diff --git a/defaults/main.yml b/defaults/main.yml index 92c7822..09c2b68 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,7 @@ gitea_gpg_key: '7C9E68152594688862D62AF62D9AE806EC1592E2' gitea_gpg_server: 'hkp://keyserver.ubuntu.com:80' gitea_backup_on_upgrade: false gitea_backup_location: "{{ gitea_home }}/backups/" +submodules_versioncheck: false # gitea in the linux world gitea_group: 'gitea' diff --git a/tasks/main.yml b/tasks/main.yml index cf2ae75..e62be44 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: perform optional versionscheck + ansible.builtin.include_tasks: versioncheck.yml + when: submodules_versioncheck|bool + - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: diff --git a/tasks/versioncheck.yml b/tasks/versioncheck.yml new file mode 100644 index 0000000..dca3e47 --- /dev/null +++ b/tasks/versioncheck.yml @@ -0,0 +1,46 @@ +--- +- name: Create directory for versionscheck + become: true + ansible.builtin.file: + path: '/etc/.ansible-version' + state: directory + mode: 0755 + when: submodules_versioncheck|bool + +- name: check playbook version + become: true + ansible.builtin.slurp: + src: "/etc/.ansible-version/{{ playbook_version_path }}" + register: playbook_version + when: submodules_versioncheck|bool + ignore_errors: true + failed_when: false + +- name: Print remote role version + ansible.builtin.debug: + msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}" + when: submodules_versioncheck|bool + +- name: Print locale role version + ansible.builtin.debug: + msg: "Local role version: '{{ playbook_version_number|string }}'." + when: submodules_versioncheck|bool + +- name: Check if your version is outdated + ansible.builtin.fail: + msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!" + when: + - playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck|bool + +- name: check if '/etc/ansible-version/' is empty + ansible.builtin.find: + paths: '/etc/ansible-version/' + register: filesFound + +- name: write new version to remote disk + become: true + ansible.builtin.copy: + content: "{{ playbook_version_number }}" + dest: "/etc/.ansible-version/{{ playbook_version_path }}" + mode: '0644' + when: submodules_versioncheck|bool diff --git a/vars/main.yml b/vars/main.yml index b473a40..bb77064 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -8,3 +8,6 @@ gitea_go_arch_map: armv5l: 'arm-5' gitea_arch: "{{ gitea_go_arch_map[ansible_architecture] | default(ansible_architecture) }}" + +playbook_version_number: 5 # should be int +playbook_version_path: 'do1jlr.gitea.version'