Skip to content

Instantly share code, notes, and snippets.

@alecnmk
Created February 16, 2016 08:41
Show Gist options
  • Save alecnmk/d2d9299b4b8009befe0c to your computer and use it in GitHub Desktop.
Save alecnmk/d2d9299b4b8009befe0c to your computer and use it in GitHub Desktop.
ansible conditionals example
---
- 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