Created
December 21, 2020 15:29
-
-
Save zeitounator/e00d77d73e326e7bc5ca55124b6f401f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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