Apologies if this is a FAQ, but I haven't found been able to find it anywhere.
I keep wanting a pattern where something happens if a variable is true and something positively doesn't happen if the variable is false (or unset). For example having a service running or not running. Is there any way to achieve this other than having pairs of tasks with inverted when clauses?
e.g:
- name: be sure openais is running and enabled
service: name=openais state=running enabled=yes
when: enable_service_address is defined and enable_service_address
- name: be sure openais is NOT running and NOT enabled
service: name=openais state=stopped enabled=no
when: enable_service_address is not defined or not enable_service_address
Or, as an other example, creating or removing a marker file (which seems to be further complicated by needing 'copy' for create and 'file' for remove):
- name: Set standalone marker file
copy: content='' dest=/var/role-standalone
when: '"standalone" in group_names'
- name: Unset standalone marker file
file: path=/var/role-standalone state=absent
when: '"standalone" not in group_names'