1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_dotfiles.git synced 2024-08-16 16:09:49 +02:00

improved version check

This commit is contained in:
Lilian Roller 2019-05-22 10:58:27 +02:00
parent eee5d577b7
commit 7409e8be9b
No known key found for this signature in database
GPG key ID: 5215C3441797AB2B
3 changed files with 42 additions and 38 deletions

View file

@ -1,41 +1,5 @@
---
- name: Create directory for versionscheck
become: yes
file:
path: '/etc/ansible-version'
state: directory
mode: 0755
when: submodules_versioncheck|bool
- name: check playbook version
become: yes
slurp:
src: "{{ playbook_version_path }}"
register: playbook_version
when: submodules_versioncheck|bool
ignore_errors: yes
- name: Print local version
debug:
msg: "Local role version: '{{ playbook_version_number|string }}'."
when: submodules_versioncheck|bool
- name: Print remote version
debug:
msg: "Remote role version: '{{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}'."
when: submodules_versioncheck|bool
- name: Check if your version is outdated
fail:
msg: "Your current ansible module has the version '{{ playbook_version_number }}' and is outdated. Please update it!"
when:
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck|bool
- name: write new version to remote disk
become: yes
copy:
content: "{{ playbook_version_number }}"
dest: "{{ playbook_version_path }}"
- include_tasks: versioncheck.yml
when: submodules_versioncheck|bool
- name: install the latest libselinux-python package

40
tasks/versioncheck.yml Normal file
View file

@ -0,0 +1,40 @@
---
- 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: "{{ playbook_version_path }}"
register: playbook_version
when: submodules_versioncheck|bool
ignore_errors: yes
changed_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: write new version to remote disk
become: true
copy:
content: "{{ playbook_version_number }}"
dest: "{{ playbook_version_path }}"
when: submodules_versioncheck|bool

View file

@ -9,5 +9,5 @@ bash:
keyboard: '$(if [[ $(id -u) -ne 0 ]];then echo "\[\033[01;33m\]"; else echo "\[\033[01;31m\]"; fi) $(if [[ $? == 0 ]]; then printf "\xE2\x9D\xA4"; fi) \[\033[01;32m\]\u\[\033[01;36m\]@\[\033[01;32m\]\H\[\033[01;34m\] <\A> \[\033[01;35m\] \j \[\033[01;36m\] \w \[\033[01;33m\]\n\[\033[01;33m\] $(git branch 2>/dev/null | sed -n "s/* \(.*\)/\1 /p")$\[\033[01;00m\] '
playbook_version_number: 102 # integer without dots
playbook_version_number: 103 # integer without dots
playbook_version_path: '/etc/ansible-version/role_dotfiles_chaos-bodensee_github.version'