published
Run in Cisco Cloud IDE

dnac_ansible_workflows

Sample workflows to automate Cisco Catalyst Center configurations through cisco.dnac ansible workflow modules. This include Playbooks, Sample inputs and Sample Inventory files.

DNAC Ansible Workflows

This repository contains a collection of Ansible workflows for automating Catalyst Center workflows. These workflows help streamline network provisioning, configuration, and management by leveraging the power of Ansible automation.

Table of Contents

Prerequisites

Before using these Ansible workflows, ensure that you have the following prerequisites:

  • Ansible installed on your machine
  • Access to a Cisco Catalyst Center instance
  • Proper network connectivity to interact with the Catalyst Center APIs

Installation

Python 3.7+ is required to install iac-validate. Don't have Python 3.7 or later? 
See Python 3 Installation & Setup Guide https://realpython.com/installing-python/
Create your python virtual environment using commend:
```bash
    python3 -m venv python3env --prompt "AnsiblePython3 VENV"
    source python3env


1. Clone this repository to your local machine:

```bash
git clone https://github.com/DNACENSolutions/dnac_ansible_workflows.git
  1. Navigate to the project directory:

    cd dnac_ansible_workflows
  2. Install the required dependencies:

     pip install -r requirements.txt
  3. Install the collection (Galaxy link):

    ansible-galaxy collection install cisco.dnac --force
  4. Create your inventory
    a. Inventory:
    This folder contains inventory file for your dev, lab, sandbox or production env which will be utilised by swim playbooks.

    Create your inventory file in below template format to utilize the swim playbooks.

    The template for the inventory file is:

        cat inventory/demo_lab/001-dnac_inventory_template.yml

    Setup up your ansible python interpretor following suitable method for your environment : https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

    b. Hairarchical variable files for inputs

    The second folder of the workflows contains playbook and var files for workflows.
    Example:
        workflows/swim
        playbooks/
            swim_workflow_playbook.yml
        vars/
            vars_swim.yml
    
  5. Var files:
    Update var file with your details and parameter to control playbook

  6. Playbook:
    The playbooks can be directly used without any change when inventory and var files created in the above templates.

  7. Executing playbook (Sample):

How to Generate your hosts inventory from Cisco Catalyst Center using inventory_gen playbook:

For brownfield Catalyst Center (Network already discovered in Catalyst Center) with devices are in inventory, then automated inventory generation can be performed through inventory_gen playbook. Following the below Steps:

i. Create a basic inventory file with Cisco Catalyst Center Inputs in inventory folder. for example demo_inv.yml

```bash
    #Inventory file for demo_lab
    catalyst_center_hosts:
        hosts:
        <dnac hostname >:
        dnac_debug: false
        dnac_host: <Cisco Catalyst Center IP Address> #(Mandatory) Cisco Catalyst Center Ip address
        dnac_password: <Cisco Catalyst Center UI admin Password> #(Mandatory) 
        dnac_port: 443 #(Mandatory) 
        dnac_username: <Cisco Catalyst Center UI admin username> #(Mandatory) 
        dnac_verify: false #(Mandatory) 
        dnac_version: <Cisco Catalyst Center Release version> #(Mandatory)  Example: 2.3.5.3
```

Here are a few examples of Ansible workflows available in this repository:

Example 1: Swim upgrade, this include uploading the images, golden tagging the image filtered location and device family and distributed and activating images on the networkk devices.

 ansible-playbook -i ./inventory_dnaccluster ./workflows/swim/playbook/swim_workflow_playbook.yml --extra-vars VARS_FILE_PATH=< Vars File PATH (Full Path or relative path from playbook)> -vvvv

Example 2: Create Sites, buildings floors using playbook : workflows/sites/playbook/site_hierarchy_playbook.yml

 ansible-playbook -i ./inventory_dnaccluster ./workflows/sites/playbook/site_hierarchy_playbook.yml --extra-vars VARS_FILE_PATH=./../vars/site_hierarchy_design_vars_.yml

Feel free to explore the playbooks/ directory for more examples and use cases.

Attention macOS users:

If you're using macOS you may receive this error when running your playbook:
objc[34120]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[34120]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We can't safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
ERROR! A worker was found in a dead state
If that's the case try setting this environment variable:

    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

Update

Getting the latest/nightly collection build

Clone the dnacenter-ansible repository.

 git clone git@github.com:DNACENSolutions/dnac_ansible_workflows.git

Go to the dnacenter-ansible directory

 cd dnac_ansible_workflows

Pull the latest master from the repo

    git pull origin master

Contributing

Contributions are welcome! To contribute to this project, follow these steps:

Fork the repository.
Create a new branch for your feature or bug fix.
Make your changes and commit them with descriptive commit messages.
Push your changes to your fork.
Submit a pull request to the main branch of this repository.

Code of Conduct

This collection follows the Ansible project's Code of Conduct. Please read and familiarize yourself with this document.

Releasing, Versioning and Deprecation:
Version (Beta) : More enhancement might follow based on usage feedback

View code on GitHub

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.