DNA Center Sites and Settings with Ansible

This is a sample repository illustrating how to use the wwt.ansible_dnac collection to create a site hierarchy and associated network settings.

The inventory used in these examples is part of a lab available from WWT Network Automation with Ansible + DNA Center Lab but you can modify the inventory and variables for any environment you have access to.

Setup

If you are testing out this sample on your own environment you will need to tackle a couple of things to get started.

TIP: Review the README.md for the collection for full installation and dependencies for the collection.

  1. Clone this repository

    git clone https://github.com/jandiorio/dnac_site_settings_example

  2. Install the Python dependencies

    pip install requests geopy timezonefinder==3.4.2

  3. Install the wwt.ansible_dnac collection

    ansible-galaxy collection install wwt.ansible_dnac

  4. Modify inventory/hosts.yml to match your environment

NOTE: The DNA Center REST API Bundle needs to be enabled on DNA Center. Find out how here.

Setup

Creating Sites

This sample playbook demonstrates how you can use the wwt.ansible_dnac Ansible collection to create sites on DNA Center.

In DNA Center, there are three different types of sites; area, building, floor. Each of these types of sites take slighly different input data to create the objects in DNA Center.

  1. Open the vars/dnac_sites.yml file and review the sample sites data

  2. Take note of the data structures for each type of site (area, building, floor)

  3. Review the dnac_site module documentation

    ansible-doc wwt.ansible_dnac.dnac_site

  4. Open the playbook playbooks/create-hierarchy.yml

  5. Review the playbook

  6. Execute the playbook ansible-playbook -i inventory/hosts.yml playbooks/create-hierarchy.yml -e "{'host_groups':'dna_2_dnac','desired_state':'present'}" --ask-vault-pass

The host_groups extra_var can point to the group or host in your inventory.

DNA Center will require a building address and the latitude/longitude when creating a building. The playbook illustrates using a lookup plugin to populate the latitude/longitude. The lookup plugin is located in the plugins/lookup directory of the collection. You could optionally resolve the values manually and include them in your dataset.

Create Site Hierarchy

Creating Settings

The network settings section of DNA Center allows you to configure the common settings associated with the places in your network. These settings might include: timezones, DNS settings, DHCP settings, NTP Servers, and serveral others. This sample playbook will illustrate how to use the wwt.ansible_dnac collection to manage these settings.

  1. Open the vars/dnac_settings.yml, vars/dnac_credentials.yml and the vars/dnac_timezones.yml files.

  2. Review the format of the YAML data that will be used in the second playbook

  3. Open the playbooks/create-network-settings.yml playbook

  4. Review each task and where there is a new module, review the documentation

    ansible-doc wwt.ansible_dnac.dnac_ntp

    TIP: Replace the module name with the one of interest for the task you are reviewing.

  5. Execute the playbook

    ansible-playbook -i inventory/hosts.yml playbooks/create-network-settings.yml -e "{'host_groups':'dna_2_dnac','desired_state':'present'}" --ask-vault-pass

    NOTE: The host_groups extra_var can point to the group or host in your inventory.

Each of the network settings can be applied globally or at any level in the hierarchy. This allows you to override global settings at different levels in the hierarch with the appropriate settings. This playbooks illustrates applying different settings in different sites using the timezone.

The dnac_timezone module also allows you to provide a location or pass in the timezone. If you pass in a location, a lookup is performed to resolve the location to a timezone using the timezonefinder python library.

Wrap Up

This example use case shows how to utilize the wwt.ansible_dnac collection to configure your DNA Center environment from Ansible using the DNA Center as a Platform feature.

Here are some useful links relating to this use case:

This repository is featured on the Cisco DevNet Code Exchange.

published

The webinar below was hosted by Redhat and delivered by Jeff Andiorio of World Wide Technology on 8/7/2018.

WWT / Redhat Ansible Webinar

AnsibleFest 2019 Presentation
DO I CHOOSE ANSIBLE, DNA CENTER OR BOTH?

Additional slides providing an overview of the modules can be found here: Ansible DNA Center Modules Overview

Collection on Ansible Galaxy

Use Case

This use case provides a step-by-step walk-through with functional playbooks for how to use Ansible modules to manage the sites and settings in Cisco DNA Center. Using Cisco DNA Center and Ansible together in this way offers the opportunity to develop workflows that accommodate heterogeneous environments.

The inventory used in these examples is part of a lab available from WWT Network Automation with Ansible + DNA Center Lab. You can modify the inventory and variables to align with any environment to which you have access.

Business Summary
Our networks consist of multiple technical domains and sometimes multiple different OEMs, thus requiring our automation strategy to encompass these areas. Combining Cisco DNA Center as a platform with Ansible provides a flexible and robust automation strategy allowing integration across multiple domains and heterogeneous environments.
View code on GitHub
  • Owner

  • Contributors

    +2Github contributors
  • Categories

  • Products

    Catalyst Center
  • Programming Languages

  • License

    GNU General Public License v3.0

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.