Skip to content

Collection of code samples for ACI programmability, including basic Ansible playbooks and Python scripts for DevNet Workshop DEVWKS-1309

Notifications You must be signed in to change notification settings

CiscoDevNet/aci_workshop_code_samples

Repository files navigation

aci_workshop_code_samples

Summary


Collection of simple code samples for ACI programmability. Includes beginner level ansible playbooks and python code snippets used or referenced in DevNet Workshop DEVWKS-1309.

This repository contains sample code for automating various types of tasks relating to ACI configuration and initial ACI fabric bringup.

Following are the step by step instructions for the Cisco Live Devnet Workshop. The samples include both Ansible playbooks and Python scripts utilizing Cobra SDK.

Workshop Test APICs

https://128.107.232.40 (admin , cisco12345)

https://128.107.232.41 (admin , cisco12345)

https://128.107.232.42 (admin , cisco12345)

https://128.107.232.43 (admin , cisco12345)

Workshop Instructions


I. Environment Setup


This is using Python 2. It is recommended to run this package in a virtual environment.

1. Open Terminal application

Terminal

2. Change to home directory

cd

3. Install virtual environment package (if not installed )

virtualenv --version

If the command is not recognized, install virtualenv with the following instructions, else go to step 4.

sudo pip install virtualenv

4. Check your default version of Python

python --version

5. Create a virtual environment with python 2.7

virtualenv aci-workshop --python=/usr/bin/python2.7

6. Activate the virtual environment

source aci-workshop/bin/activate

7. Clone "aci_workshop_code_samples" repository

git clone https://github.com/CiscoDevNet/aci_workshop_code_samples.git

8. Change directory

cd aci_workshop_code_samples

9. Install requirements

pip install -r requirements.txt

10. Install Ansible

pip install ansible==2.7.8

11. Download Cobra SDK egg files

THIS STEP HAS ALREADY BEEN DONE FOR YOU:

Download cobra eggs:

cd $HOME/Downloads
wget https://www.dropbox.com/s/koiljhrra16g30o/acicobra-3.2_7f-py2.7.egg
wget https://www.dropbox.com/s/esohbv25bwtoj68/acimodel-3.2_7f-py2.7.egg

The 2 egg files have been placed in your Downloads directory

12. Change directory

cd $HOME/Downloads

13. Install Cisco APIC Python SDK - acicobra egg file

easy_install -Z acicobra-3.2_7f-py2.7.egg

14. Install Cisco APIC Python SDK - acimodel egg file

easy_install -Z acimodel-3.2_7f-py2.7.egg

15. Test APIC Access

Browse to your APIC simulator: https://<ip address> and login

II. Ansible Playbook - ACI Configuration for Firewall Solution


Create a Unique Tenant

16. In Terminal, return to "aci_workshop_code_samples" directory

cd $HOME/aci_workshop_code_samples

17. Open the file "tenant_create.yml" using Atom

atom tenant_create.yml

18. Make these changes to the file: tenant_create.yml

Verify or make changes to insure these fields are as noted:

	aci_hostname:  <your APIC simulator>
	tenant:        <your unique tenant name>
	description:   <some description>

SAVE YOUR CHANGES - click on File, click on Save

19. Return to command line and execute the Playbook

ansible-playbook tenant_create.yml

20. Verify tenant was created in Web UI

  Browse to your APIC simulator: https://<ip address> and login

Run the Ansible Playbook to create ACI Firewall Config

21. In Terminal, change directory to aci_workshop_code_samples/playbook_vars/aci_workshop_fab1

cd $HOME/aci_workshop_code_samples/playbook_vars/aci_workshop_fab1

22. Open the file "aci_fw_config_vars.yml" using Atom

atom aci_fw_config_vars.yml

23. Modify this file: aci_fw_config_vars.yml

Note: this is the input variable file for the Playbook we will run later.

Verify or make changes to insure these fields are as noted:

	aci_hostname:  <your APIC simulator>
	aci_tenant:    <your unique tenant name>

SAVE YOUR CHANGES - click on File, click on Save

24. In Terminal, change directory to aci-workshop

cd $HOME/aci_workshop_code_samples

25. Return to command line and execute the Playbook

ansible-playbook run_firewall_build_demo.yml -e @./playbook_vars/aci_workshop_fab1/aci_fw_config_vars.yml

26. Login to APIC to Verify/Monitor changes within your tenant's Networking section

	Browse to your APIC simulator: https://<ip address> and login

III. Python Scripts (with Cobra SDK) - ACI Fabric Bringup and Base Configuration


Security Policy Configuration

27. Change to python_scripts directory

cd $HOME/aci_workshop_code_samples/python_scripts

28. Open the file "policy_cfg_source.yml" using Atom

atom policy_cfg_source.yml

29. Modify this file: policy_cfg_source.yml

Verify or make changes to insure the tenant name is correct:

	tenants:
      -
        name: "<this is YOUR tenant you just created>"

SAVE YOUR CHANGES - click on File, click on Save

30. Return to command line, and view the Python script options

python policy_cfg.py -h

31. Execute the python script

python policy_cfg.py -a <your apic> -u admin -p <password> -f policy_cfg_source.yml

33. Login to APIC to Verify/Monitor changes within your tenant's Contract section

	Browse to your APIC simulator: https://<ip address> and login

Time Permitting: Fabric Discovery

33. Change to python_scripts directory

cd $HOME/aci_workshop_code_samples/python_scripts

34. Return to the command line, and view the Python script options

python fabric_site_specific.py -h

35. Execute the python script

python fabric_site_specific.py -a <your apic> -u admin -p <password> -f fabric_site_acisim.yml

About

Collection of code samples for ACI programmability, including basic Ansible playbooks and Python scripts for DevNet Workshop DEVWKS-1309

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages