Not in that manner, you need to use a jinja within `service_offering`
instead:
service_offering: '{{ item.cs_instance|default(cs_template, true) }}'
That will use cs_template if cs_instance is undefined or falsy
On Wed, May 20, 2020 at 1:42 PM Aidan Wong <[email protected]> wrote:
> Hi
>
> Is it possible to write jinja "if" conditionals within a playbook like so?
> If not can someone suggest an alternative?
>
> - name: Deploy the VMs without an anti-affinity group.
> cs_instance:
> zone: "{{ cs_zone }}"
> api_region: "{{ cs_api_region | upper }}"
> display_name: "{{ item.instance }}"
> name: "{{ item.instance | regex_replace('\\.','-') }}"
> project: "{{ cs_network }}"
> networks: [ "{{ cs_network }}" ]
> template: "{{ cs_template }}"
> {% if item.cs_instance is null %}
> service_offering: "{{ cs_template }}"
> {% else %}
> service_offering: "{{ item.cs_instance }}"
> {% endif %}
> state: "{{ cs_state }}
> poll_async: "yes"
> tags: "{{ final_tags }}"
> user_data: "{{ user_data | string }}"
> delegate_to: localhost
> loop: "{{ myvmsfqdn }}"
> when: cs_anti_affinity_group is not defined and cs_state == "started"
>
>
>
> Thanks
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/567771c1-88fb-4f1c-b26e-5c2a3ee4eb78%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/567771c1-88fb-4f1c-b26e-5c2a3ee4eb78%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
Matt Martz
@sivel
sivel.net
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-5vCMCJ%2BY8_%3DpBt1agXd3Q8MkKq2eNrYn8fnYC1Q%3DGnw%40mail.gmail.com.