Question:
I am looking for a way to perform a task when ansible variable is not registers /undefined e.g
1 2 3 4 5 |
-- name: some task command: sed -n '5p' "{{app.dirs.includes}}/BUILD.info" | awk '{print $2}' when: (! deployed_revision) AND ( !deployed_revision.stdout ) register: deployed_revision |
Answer:
From the ansible docs:
If a required variable has not been set, you can skip or fail using Jinja2’s defined test. For example:
1 2 3 4 5 6 7 8 |
tasks: - shell: echo "I've got '{{ foo }}' and am not afraid to use it!" when: foo is defined - fail: msg="Bailing out. this play requires 'bar'" when: bar is not defined |
So in your case, when: deployed_revision is not defined
should work