This seems to be working, but is there a more readable way to write this?

size: "{{ 300 if 'string1’ in ansible_fact or 'string_2' in ansible_fact or 
'string_3' in ansible_fact or 'string_4' in ansible_fact else 100 if 
'string_5' in ansible_fact or 'string_6' in ansible_fact or 'string_7' in 
ansible_fact else 200 if 'string_8' in ansible_fact }}"




On Monday, August 7, 2017 at 8:08:40 PM UTC-7, Ryan wrote:
>
> I need to set some variables that are the same no matter the client, and 
> other variables need to be set conditionally based on values from Ansible 
> facts.  Basically I need an if/else case statement.  What is the correct 
> way to do this?
>
> Some simple examples can be found here (
> http://docs.ansible.com/ansible/latest/playbooks_conditionals.html#conditionals)
>  
> but  this doesn't cover else conditions, and if I remove the second 
> instance of VAR4, and put in condition that is not met, it still sets VAR4, 
> when the match doesn't exist, so it seems like the "when" is not being 
> evaluated.
>
>
> ---
>
> - name: Playbook Name
>
>   hosts:  all
>
>   gather_facts: yes
>
>   tasks:
>
>  
>
>      - name: Set variables
>
>        vars:
>
>          VAR1: 5
>
>          VAR2: 10
>
>          VAR3: 0
>
>  
>
>          VAR4: 100
>
>          when: (ansible_some_fact == "some_value1") or
>
>                (ansible_some_fact == "some_value2")
>
>  
>
>          VAR4: 200
>
>          when: (ansible_some_fact == "some_value3") or
>
>                (ansible_some_fact == "some_value4")
>

-- 
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/a9333d05-4408-4317-8752-44f85e3e8a98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to