I like to use the ternary operator in cases like these (not as "thick" as 
the conditionals):

vars:
  openais_enabled: "{{ 'yes' if enable_service_address is defined and 
enable_service_address else 'no' }}"
  openais_running: "{{ 'running' if enable_service_address is defined and 
enable_service_address else 'stopped' }}"

Or, to avoid variables and have the logic all in the task definition:

- name: be sure openais is running and enabled
  service:
    name: openais
    state: "{{ 'running' if enable_service_address is defined and 
enable_service_address else 'stopped' }}"
    enabled: "{{ 'yes' if enable_service_address is defined and 
enable_service_address else 'no' }}"

Cheers,
Christian


On Monday, January 5, 2015 3:13:31 PM UTC+1, Michael DeHaan wrote:
>
> Alternatively, something like this:
>
> vars:
>    openais_enabled: "{% if enable_service_address is defined and 
> enable_service_address %}yes{% else %}no{% endif %}
>    openais_running: "{% if enable_service_address is defined and 
> enable_service_address %}running{% else %}stopped{% endif %}
>
> and in tasks:
>
> - name: be sure openais is running and enabled
>   service: name=openais state={{ openais_running }} enabled={{ 
> openais_enabled }}
>
> I'm not sure I really like that, as the conditional is a bit thick, though.
>
> More so just sharing for completeness.
>
>
> On Mon, Jan 5, 2015 at 6:27 AM, Jon Warbrick <jw...@cam.ac.uk 
> <javascript:>> wrote:
>
>> On Wed, 17 Dec 2014, Brian Coca wrote:
>>
>>  not currently, what you have is what works.
>>>
>>
>> Ta. At least I wasn't missing something obvious...
>>
>>
>> Jon.
>>
>> -- 
>> Jon Warbrick
>> Information Systems Manager, University of Cambridge Information Services
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e5769fe4-dc8b-46f1-9bf3-3b8d3fb0c835%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to