This repository contains Ansible playbooks and roles for automating Cisco APIC (Application Policy Infrastructure Controller) configurations using the REST API and Bulk ACI. The code provides a structured approach to configure ACI policies, manage tenants, bridge domains, application profiles, and more. The repository is designed to streamline the process of managing ACI infrastructure with the power of automation.
- Introduction
- Prerequisites
- Directory Structure
- Installation and Setup
- Usage
- Roles Overview
- Testing
- Contributing
- License
This project leverages Ansible to automate configuration tasks in Cisco's APIC using the ACI REST API and Bulk operations. The aim is to simplify the deployment and management of ACI policies, including the configuration of application profiles, tenants, and port bindings.
Before using this Ansible automation, ensure you have the following prerequisites:
-
Ansible version 2.9 or higher installed.
-
Cisco ACI APIC credentials (username and password).
-
Python 3.x and necessary libraries (e.g.,
requests
,pyyaml
). -
Cisco ACI REST API access configured in your environment.
-
Ansible collections for Cisco ACI, which can be installed via:
ansible-galaxy collection install cisco.aci
The directory structure is as follows:
.
├── Export_inventory.py # Python script for exporting inventory data
├── host_vars # Directory containing host variable files
│ └── localhost.yml # Host variable file for localhost
├── playbook.yaml # Main Ansible playbook for orchestrating tasks
├── README.md # Project documentation
└── roles # Ansible roles for different ACI configurations
├── AAEP_config # Role for configuring AAEP settings
├── Port_Binding_config # Role for configuring port bindings
└── Tenant_config # Role for configuring tenant settings
- Export_inventory.py: A Python script to export the APIC inventory into a format compatible with Ansible.
- host_vars/: Directory containing variable files for different hosts, with
localhost.yml
being the configuration file for localhost. - playbook.yaml: Main playbook that includes all the tasks to be automated.
- roles/: Contains reusable roles for different ACI configuration tasks:
- AAEP_config: Configures AAEP (Attachable Access Entity Profile) settings.
- Port_Binding_config: Configures port bindings in the ACI fabric.
- Tenant_config: Manages tenant configurations and policies.
-
Clone the Repository:
Clone this repository to your local machine using Git:
git clone https://github.com/haviethung3004/ACI_Ansible_Rest_API.git cd aci-automation
-
Install Dependencies:
Install Ansible and the required collections:
pip install ansible ansible-galaxy collection install cisco.aci
-
Configure Inventory:
Edit the
host_vars/localhost.yml
file to include your APIC credentials and any additional configuration required for your environment. -
Configure Variables:
Each role in the
roles
directory may have its own set of variables defined indefaults/main.yml
orvars/main.yml
. Ensure these are configured according to your ACI environment.
Once the setup is complete, you can use the following command to run the playbook:
ansible-playbook playbook.yaml -i host_vars/localhost.yml
This will execute the playbook, applying the configurations defined in the respective roles.
To apply tenant configurations, you can run the playbook with a specific tag:
ansible-playbook playbook.yaml -i host_vars/localhost.yml --tags "tenant"
The AAEP_config
role is responsible for configuring the Attachable Access Entity Profile (AAEP) in the ACI fabric. AAEPs define the configuration for how devices (like switches) are connected to the ACI fabric.
aci_aaep_name
: Name of the AAEP.aci_aaep_ports
: List of ports to be included in the AAEP.
The Port_Binding_config
role configures port bindings within the ACI fabric, ensuring that physical or virtual ports are properly associated with the correct profiles.
aci_binding_name
: The name for the port binding.aci_binding_ports
: List of ports for binding.
The Tenant_config
role manages the configuration of tenants, application profiles, bridge domains, and subnets within ACI.
aci_tenant_name
: Name of the tenant.aci_application_profiles
: List of application profiles to be configured for the tenant.aci_bridge_domains
: List of bridge domains to be configured.
Unit tests are located in the roles
directories under the tests
folder. You can run the tests using the following command:
ansible-playbook roles/AAEP_config/tests/test.yml
You can extend these tests to match your own environment.
This project is licensed under the MIT License.