Created
February 16, 2016 08:41
-
-
Save alecnmk/d2d9299b4b8009befe0c to your computer and use it in GitHub Desktop.
ansible conditionals example
This file contains 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
--- | |
- name: put simple template file | |
template: src=test_template.txt.j2 dest=/tmp/test.txt | |
vars: | |
text: "{{test_text}}" | |
- name: read variable for consequent conditional execution | |
shell: cat /tmp/test.txt | |
register: existing_text | |
- name: create another test file if contents of /tmp/test.txt == expected_text | |
template: src=test_template2.txt.j2 dest=/tmp/test2.txt | |
register: result | |
when: existing_text['stdout'] == expected_text | |
vars: | |
text: 'another text file' | |
- name: remove another test file if contents of /tmp/test.txt != expected_text | |
file: path=/tmp/test2.txt state=absent | |
when: result | skipped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment