Hello, I'm new to Ansible and JINJA, I can't figure out how to get this
task to run conditionally.
Here's my playbook:
- name: Deploy topology using ACI model
hosts: '*apic1'
gather_facts: no
roles:
- role: datacenter.aci-model
aci_model_data: '{{ aci_topology }}'
tags: aci
Here's a snippet of my inventory file:
vars:
aci_topology:
tenant:
- app:
- epg:
- name: WEB-EPG
domain:
- name: Phys-Dom
type: phys
- name: VMM-Dom
type: vmm
vm_provider: vmware
static_paths:
- deploy_immediacy: immediate
encap_id: 2
interface: 1/1
interface_mode: untagged
interface_type: leaf
leafs: [201]
pod_id: 1
- deploy_immediacy: immediate
encap_id: 2
interface: 1/1
interface_mode: untagged
interface_type: leaf
leafs: [202]
pod_id: 1
bd: WEB-BD
- name: APP-EPG
domain:
- name: Phys-Dom
type: phys
- name: VMM-Dom
type: vmm
vm_provider: vmware
bd: APP-BD
As you can see in the inventory, some EPGs may not have static paths
defined.
My role has a task that I would like to run only if static paths are
defined in the EPG.
Here's the task:
- name: Create EPG static paths
aci_static_binding_to_epg:
<<: *aci_login
tenant: '{{ item.tenant_name }}'
ap: '{{ item.tenant_app_name }}'
epg: '{{ item.tenant_app_epg_name }}'
deploy_immediacy: immediate
encap_id: '{{ item.tenant_app_epg_static_paths_encap_id }}'
interface: '{{ item.tenant_app_epg_static_paths_interface }}'
interface_mode: '{{ item.tenant_app_epg_static_paths_interface_mode
}}'
interface_type: '{{ item.tenant_app_epg_static_paths_interface_type
}}'
leafs: '{{ item.tenant_app_epg_static_paths_interface_leafs }}'
pod_id: '{{ item.tenant_app_epg_static_paths_pod_id }}'
with_items: '{{
aci_model_data|aci_listify("tenant","app","epg","static_paths") }}'
I'm not exactly sure what I'm doing, I've tried adding the following:
when: item.tenant_app_epg_static_paths is defined
when: item.tenant_app_epg_static_paths_interface is defined
The first gives me an error that the dictionary has no
attribute tenant_app_epg_static_paths_interface_leafs. I'm guessing it's
trying to run the task on one of the EPGs with no static path defined.
The 2nd runs, but skips the WEB-EPG EPG.
Any suggestions on how I can accomplish this?
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/e1a00559-0e24-4907-8cfd-cd048866713d%40googlegroups.com.