Cisco ACI – Automation

Cisco ACI Supports several methods of automation or infrastructure as code. For this example, I will be using Terraform to give examples of setting up different fabric policies using the Cisco ACI lab.

Setup

To get this setup, I have several things to do

Lab

Once the lab has been setup and VPN connected to the ACI APIC will be available at https://10.10.20.14/.
Navigate to Fabric >> Access Policies >> Switches >> Leaf Switches >> Profiles
This is just to show what is currently configured as default.

Create a New ACI Terraform Project

To get the CI/CD pipeline setup we first need a project. I have previously detailed the steps to setup the GitLab SSH key.

git@gitlab.com:ntwklab1/aci.git

Next is to setup all the files required. I will be using the GitLab Terraform state. I have detailed this in more detail in this post. In summary, the Terraform state files are to live on GitLab allowing all users of the repo to use the same state files. The Terraform state files need to be created first. I am not going to perform a migration, everything will be new.

Files I will create

  • .gitignore
  • .gitlab-ci.yml
  • backend.tf
  • main.tf

.gitignore

.gitlab-ci.yml

backend.tf

main.tf

This will be a temporary file just to get the new Terraform state files created in GitLab

Push To GitLab

Using Git, just on the main branch, push these files up to the GitLab project.

As the initial pipeline runs the Terraform state file in GitLab will be created.

Install GitLab Runner on Mac

The Terraform state was created using an already created GitLab runner on my Ubuntu VM. I will be using my Mac for this due to the VPN connection to the ACI DevNet lab.

I have created the new runner, the next steps are to install and register the runner.
As in the setup post for the GitLab runner, it is best to run this as sudo and include the networking command.

Create a new network called gitlab-runner-net

Next is to download and install the GitLab runner. I found the official way to install the service would only run under the user mode, but wouldn’t pick up any jobs. It needed to be run as sudo but that wouldn’t install as a service, any time it ran it was with sudo gitlab-runner run command which was nice as I could see the output, but not in the background.

To work around this, I used homebrew.

Now that is installed. It is time to register the runner.

Other options include, selecting docker as the executor and alpine as the default docker image.

Check the newly configured file for the settings. These can be modified, just restart the runner gitlab-runner restart

Run the runner as sudo to connect, sudo gitlab-runner run

Terraform

Now the actual config is ready for the ACI lab. The main.tf contains the Terraform to configure;

  • Interface Policies
  • Interface Policy Groups
  • Interface Profile
  • Interface Selector
  • Switch Profile
  • VLAN Pool
  • Physical Domain
  • AAEP

Running

A change to the main.tf file will trigger the GitLab runner.

The pipeline will run the first three stages automatically and then wait for the deploy to be manually triggered.
The first time I ran this, there was an error with the deploy stage due to interface overlaps. I will go on to fix this manually after.

I have logged into the GUI and removed the pre-configured leaf profiles, which has cleared the conflicting configuration.

The build stage to recreate the plan needed to be rerun, so only the single change was required.

And lastly, to destroy the configuration.

Leave a Comment

Your email address will not be published. Required fields are marked *