From f5de2a2056d2b78b255e2f222953a79d15b7ab60 Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 4 Feb 2021 14:43:54 +0100 Subject: [PATCH] implement versionscheck --- .yamllint | 8 ++++++++ defaults/main.yml | 2 ++ tasks/main.yml | 4 ++++ tasks/versioncheck.yml | 46 ++++++++++++++++++++++++++++++++++++++++++ vars/main.yml | 3 +++ 5 files changed, 63 insertions(+) create mode 100644 .yamllint create mode 100644 tasks/versioncheck.yml create mode 100644 vars/main.yml diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..cb32cb1 --- /dev/null +++ b/.yamllint @@ -0,0 +1,8 @@ +--- +extends: default + +rules: + # 150 chars should be enough, but don't fail if a line is longer + line-length: + max: 150 + level: warning diff --git a/defaults/main.yml b/defaults/main.yml index 73c252d..ab89c89 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,6 @@ --- +# enable version check for this role? (true is recomended) +submodules_versioncheck: false nginx_sites: {} diff --git a/tasks/main.yml b/tasks/main.yml index 8219933..1e0b3ad 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: simple versionscheck + include_tasks: versioncheck.yml + when: submodules_versioncheck | bool + - name: Install nginx include_tasks: installation.yml diff --git a/tasks/versioncheck.yml b/tasks/versioncheck.yml new file mode 100644 index 0000000..1ca07b5 --- /dev/null +++ b/tasks/versioncheck.yml @@ -0,0 +1,46 @@ +--- +- name: Create directory for versionscheck + become: true + file: + path: '/etc/.ansible-version' + state: directory + mode: 0755 + when: submodules_versioncheck|bool + +- name: check playbook version + become: true + 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 + debug: + msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}" + when: submodules_versioncheck|bool + +- name: Print locale role version + debug: + msg: "Local role version: '{{ playbook_version_number|string }}'." + when: submodules_versioncheck|bool + +- name: Check if your version is outdated + 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 + find: + paths: '/etc/ansible-version/' + register: filesFound + +- name: write new version to remote disk + become: true + 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 new file mode 100644 index 0000000..aff862e --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,3 @@ +--- +playbook_version_number: 22 # should be int +playbook_version_path: 'do1jlr.nginx_roles-ansible.version'