Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Created December 21, 2020 15:29
Show Gist options
  • Save zeitounator/e00d77d73e326e7bc5ca55124b6f401f to your computer and use it in GitHub Desktop.
Save zeitounator/e00d77d73e326e7bc5ca55124b6f401f to your computer and use it in GitHub Desktop.
---
- hosts: localhost
gather_facts: false
vars:
cidre_version: "{{ lookup('file', '/tmp/VERSION', errors='ignore') | default('v0.1.0', true) }}"
tasks:
- name: Show initial version
debug:
var: cidre_version
- name: Fix version in set_fact
set_fact:
cidre_version_static: "{{ cidre_version }}"
- name: show vars
debug:
msg: "cidre_version: {{ cidre_version }} - cidre_version_static: {{ cidre_version_static }}"
- name: create the version file
copy:
dest: /tmp/VERSION
content: v1.0.0
- name: show vars
debug:
msg: "cidre_version: {{ cidre_version }} - cidre_version_static: {{ cidre_version_static }}"
$ pwd
/tmp
$ rm VERSION
rm: cannot remove 'VERSION': No such file or directory
$ ansible-playbook playbook.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] ******************************************************************************************************************************************************
TASK [Show initial version] *******************************************************************************************************************************************
[WARNING]: Unable to find '/tmp/VERSION' in expected paths (use -vvvvv to see paths)
ok: [localhost] => {
"cidre_version": "v0.1.0"
}
TASK [Fix version in set_fact] ****************************************************************************************************************************************
[WARNING]: Unable to find '/tmp/VERSION' in expected paths (use -vvvvv to see paths)
ok: [localhost]
TASK [show vars] ******************************************************************************************************************************************************
[WARNING]: Unable to find '/tmp/VERSION' in expected paths (use -vvvvv to see paths)
ok: [localhost] => {
"msg": "cidre_version: v0.1.0 - cidre_version_static: v0.1.0"
}
TASK [create the version file] ****************************************************************************************************************************************
changed: [localhost]
TASK [show vars] ******************************************************************************************************************************************************
ok: [localhost] => {
"msg": "cidre_version: v1.0.0 - cidre_version_static: v0.1.0"
}
PLAY RECAP ************************************************************************************************************************************************************
localhost : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment