APIC-EM as a dynamic inventory for ansible
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



With this python script you can use Cisco APIC-EM as a dynamic inventory for ansible.
I want to mention that I used code snippets from the project ansible-apic-em, which contains an APIC-EM ansible module.
By contrast my project uses APIC-EM as a real dynamic inventory for ansible playbooks.


  1. Place the file apicem-dynamic-inventory.py in a folder at your ansible-project. For example the folder can be called "dynamic-inventory".
  2. Edit the file and change the variables self.controllername, self.username and self.password to your own APIC-EM values.
  3. Execute a playbook with APIC-EM as the dynamic inventory.


The example playbook uses the ansible module ntc_show_command of the project ntc-ansible. Please consider that you need the module and the template-file for the command you are using (in this case show clock).

all devices

ansible-playbook regex.yml -i dynamic-inventory

limit to one location

ansible-playbook regex.yml -i dynamic-inventory --limit "mylocation"

limit to one device

ansible-playbook regex.yml -i dynamic-inventory --limit "mydevice"

returned variables

In this version the following variables are returned by the dynamic inventory as host variables:

  • macAddress
  • upTime
  • bootDateTime
  • location
  • device_ip
  • software

Following versions will also return platform as a variable. This would be useful for other ansible-modules like the ones from ntc-ansible.


  • this version doesnt return devices which have no location set in APIC-EM


This project is published with the MIT license. So feel free to use the code in your own projects.