08-19-2022 05:05 AM - edited 08-19-2022 05:08 AM
Hi experts,
I'am currently using Ansible to manage App/Epg in ACI.
Eveything work as expected to create or delete the objects.
But now, I would like a playbook that delete the epg and after that delete the app profile but only if this one is empty (no epg anymore).
If there is still an epg located in the app profile, I skip the task.
Any ideas to do that ?
Thank you
Ju
Solved! Go to Solution.
08-22-2022 05:54 AM
Hi Ju
This should work:
tasks:
- name: query all epgs under tenant/ap
cisco.aci.aci_epg:
host: "{{ apic_host }}"
username: "{{ apic_user }}"
password: "{{ apic_pass }}"
validate_certs : no
tenant: "{{ tn }}"
ap: "{{ ap }}"
state: query
register:
epgs_by_ap
- name: delete ap if empty
cisco.aci.aci_ap:
host: "{{ apic_host }}"
username: "{{ apic_user }}"
password: "{{ apic_pass }}"
validate_certs : no
tenant: "{{ tn }}"
ap: "{{ ap }}"
state: absent
when: epgs_by_ap['current'][0]['fvAp']['children'] is not defined
HTH
Marcel
08-22-2022 05:54 AM
Hi Ju
This should work:
tasks:
- name: query all epgs under tenant/ap
cisco.aci.aci_epg:
host: "{{ apic_host }}"
username: "{{ apic_user }}"
password: "{{ apic_pass }}"
validate_certs : no
tenant: "{{ tn }}"
ap: "{{ ap }}"
state: query
register:
epgs_by_ap
- name: delete ap if empty
cisco.aci.aci_ap:
host: "{{ apic_host }}"
username: "{{ apic_user }}"
password: "{{ apic_pass }}"
validate_certs : no
tenant: "{{ tn }}"
ap: "{{ ap }}"
state: absent
when: epgs_by_ap['current'][0]['fvAp']['children'] is not defined
HTH
Marcel
08-23-2022 03:31 AM
Thank you Marcel
It works perfectly.
Regards,
Ju
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide