Ansible
Execution

Step 1 - Create ansible configuration file

A good practice is to setup a configuration file for Ansible. This file is called ansible.cfg . Some of the important configuration items for the ansible.cfg file is the definition of callbacks that allow to expand the playbook output which is very useful when troubleshooting.


cat << EOF > /home/pod04/ltrdcn-3225/ansible/playbooks/aci/ansible.cfg 
[defaults]
callback_whitelist=ansible.posix.timer,ansible.posix.profile_tasks,ansible.posix.profile_roles
callbacks_enabled=ansible.posix.timer,ansible.posix.profile_tasks,ansible.posix.profile_roles
stdout_callback = community.general.yaml
EOF

Step 2 - Run the Ansible playbook

To execute an Ansible playbook you simply just use ansible-playbook. You are going to use our own host file, so you must specify -i hosts.yml, where -i is for inventory and hosts is the inventory file name. Lastly, you must specify the playbook file, site.yml.

In the terminal window in the ansible directory you should run the following command:


cd  ~/ltrdcn-3225/ansible/playbooks/aci
ansible-playbook -i hosts.yml site.yml

This command should produce the following output:

PLAY [APIC Tenant Configuration playbook] **************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************
Saturday 01 January 1970  17:11:18 -0500 (0:00:00.058)       0:00:00.058 ****** 
Saturday 01 January 1970  17:11:18 -0500 (0:00:00.057)       0:00:00.057 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE ACI TENANT VRF1] *******************************************************************************************************************************************
Saturday 01 January 1970  17:11:20 -0500 (0:00:01.680)       0:00:01.739 ****** 
Saturday 01 January 1970  17:11:20 -0500 (0:00:01.680)       0:00:01.738 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE ACI TENANT VRF2] *******************************************************************************************************************************************
Saturday 01 January 1970  17:11:20 -0500 (0:00:00.795)       0:00:02.534 ****** 
Saturday 01 January 1970  17:11:20 -0500 (0:00:00.795)       0:00:02.533 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE BRIDGE DOMAIN FOR DB] **************************************************************************************************************************************
Saturday 01 January 1970  17:11:21 -0500 (0:00:00.592)       0:00:03.127 ****** 
Saturday 01 January 1970  17:11:21 -0500 (0:00:00.592)       0:00:03.126 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE SUBNET FOR DB BRIDGE DOMAIN] *******************************************************************************************************************************
Saturday 01 January 1970  17:11:22 -0500 (0:00:00.827)       0:00:03.955 ****** 
Saturday 01 January 1970  17:11:22 -0500 (0:00:00.827)       0:00:03.954 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE BRIDGE DOMAIN FOR JAVA APP] ********************************************************************************************************************************
Saturday 01 January 1970  17:11:23 -0500 (0:00:00.804)       0:00:04.759 ****** 
Saturday 01 January 1970  17:11:23 -0500 (0:00:00.804)       0:00:04.758 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE SUBNET FOR JAVA APP BRIDGE DOMAIN] *************************************************************************************************************************
Saturday 01 January 1970  17:11:23 -0500 (0:00:00.570)       0:00:05.330 ****** 
Saturday 01 January 1970  17:11:23 -0500 (0:00:00.570)       0:00:05.329 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE ACI TENANT APPLICATION PROFILE] ****************************************************************************************************************************
Saturday 01 January 1970  17:11:24 -0500 (0:00:00.548)       0:00:05.878 ****** 
Saturday 01 January 1970  17:11:24 -0500 (0:00:00.548)       0:00:05.877 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE DATABASE EPG] **********************************************************************************************************************************************
Saturday 01 January 1970  17:11:25 -0500 (0:00:00.832)       0:00:06.711 ****** 
Saturday 01 January 1970  17:11:25 -0500 (0:00:00.832)       0:00:06.710 ****** 
ok: [10.0.226.41]

TASK [apic : CREATE JAVA APP EPG] **********************************************************************************************************************************************
Saturday 01 January 1970  17:11:25 -0500 (0:00:00.864)       0:00:07.576 ****** 
Saturday 01 January 1970  17:11:25 -0500 (0:00:00.864)       0:00:07.575 ****** 
ok: [10.0.226.41]

PLAY RECAP *********************************************************************************************************************************************************************
10.0.226.42                : ok=10   changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Playbook run took 0 days, 0 hours, 0 minutes, 8 seconds
Saturday 01 January 1970  17:11:26 -0500 (0:00:00.613)       0:00:08.189 ****** 
=============================================================================== 
Gathering Facts --------------------------------------------------------------------------------------------------------------------------------------------------------- 1.68s
apic : CREATE DATABASE EPG ---------------------------------------------------------------------------------------------------------------------------------------------- 0.86s
apic : CREATE ACI TENANT APPLICATION PROFILE ---------------------------------------------------------------------------------------------------------------------------- 0.83s
apic : CREATE BRIDGE DOMAIN FOR DB -------------------------------------------------------------------------------------------------------------------------------------- 0.83s
apic : CREATE SUBNET FOR DB BRIDGE DOMAIN ------------------------------------------------------------------------------------------------------------------------------- 0.80s
apic : CREATE ACI TENANT VRF1 ------------------------------------------------------------------------------------------------------------------------------------------- 0.80s
apic : CREATE JAVA APP EPG ---------------------------------------------------------------------------------------------------------------------------------------------- 0.61s
apic : CREATE ACI TENANT VRF2 ------------------------------------------------------------------------------------------------------------------------------------------- 0.59s
apic : CREATE BRIDGE DOMAIN FOR JAVA APP -------------------------------------------------------------------------------------------------------------------------------- 0.57s
apic : CREATE SUBNET FOR JAVA APP BRIDGE DOMAIN ------------------------------------------------------------------------------------------------------------------------- 0.55s
Saturday 01 January 1970  17:11:26 -0500 (0:00:00.613)       0:00:08.188 ****** 
=============================================================================== 
apic -------------------------------------------------------------------- 6.45s
gather_facts ------------------------------------------------------------ 1.68s
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
total ------------------------------------------------------------------- 8.13s

And the ACI fabric is now configured. If you run the command again, you will notice that Ansible indicates that the setting is ok:. Which means that the configuration is already at the intended state that you set.

You can re-run the scripts as many times as you wish and Ansible will validate that the configuration is setup this way. If you modify the script in any way, like changing the subnet IP or the mask you will notice that it will indicate changed as it modifies that configuration.

You can also run the playbook in verbose mode by adding the -v option. This will provide more information about the execution of the playbook.


ansible-playbook -i hosts.yml site.yml -v

In the case of ACI this even includes the datastructures that are being sent to the APIC. Since we are using the YAML callback, the data is presented in YAML format.

[TRIM]
TASK [apic : CREATE JAVA APP EPG] *********************************************************************************************************************************************
Saturday 01 January 1970  17:10:27 -0500 (0:00:00.805)       0:00:08.452 ****** 
Saturday 01 January 1970  17:10:27 -0500 (0:00:00.805)       0:00:08.450 ****** 
ok: [10.0.226.41] => changed=false 
  current:
  - fvAEPg:
      attributes:
        annotation: orchestrator:ansible
        descr: POD04 Java APP EPG
        dn: uni/tn-aciproglab04/ap-POD04_APP/epg-java_app
        exceptionTag: ''
        floodOnEncap: disabled
        fwdCtrl: ''
        hasMcastSource: 'no'
        isAttrBasedEPg: 'no'
        matchT: AtleastOne
        name: java_app
        nameAlias: ''
        pcEnfPref: unenforced
        prefGrMemb: exclude
        prio: unspecified
        shutdown: 'no'
        userdom: ':all:common:aciproglab04:'
[TRIM]

Step 3 - Connect to APIC to see the configuration

Click on the following link to connect to the APIC. The credentials for your login are:

  • Username: aciproglab04
  • Password: cisco.123

Note

You may need to close the Meet Cisco APIC x.x(x) by clicking the Let's Go! button, then the Get Started button


Once you logged to the APIC, you will be placed in the System Health page.

Follow these steps to get to your Tenant aciproglab04 :

  1. Click on Tenants
  2. On the seach box enter aciproglab04



The first thing you should notice is the nice message that ACI is providing to the user to highlight how this object was created via Ansible. Then you can verify under the summary page the objects created via the Ansible Playbook which includes Application EPGs, VRFfs, Bridge Domains.

You should notice from the summary page the numbers of Application EPGs, VRFfs, Bridge Domains created via Ansible. You can expand the application profiles and networking menus on the left to further see this configuration if desired.