cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
482
Views
10
Helpful
2
Replies

ACI - Ansible - Delete App profile only if empty

ju.mahieu
Level 1
Level 1

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

 

 

 

1 Accepted Solution

Accepted Solutions

Marcel Zehnder
Spotlight
Spotlight

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

View solution in original post

2 Replies 2

Marcel Zehnder
Spotlight
Spotlight

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

ju.mahieu
Level 1
Level 1

Thank you Marcel

It works perfectly.

Regards,

Ju

Save 25% on Day-2 Operations Add-On License