Giter Site home page Giter Site logo

netbox-ansible-cisco-cc's Introduction

netbox-ansible-cisco-cc

A simple NetBox integration that enables Ansible to automate devices managed by a Cisco Catalyst Center Controller.

Integration Overview

The four main elements of the integration are as follows:

  1. The NetBox data model is extended by adding two Custom Fields to the devices model:
  • Custom Field 1 is called cisco_catalyst_center, and is a Selection type field that maps to the hostname of the Cisco Catalyst Center controller:

    custom field

    The Custom Field makes use of a Choice Set called Cisco Catalyst Center Hosts which is a drop-down menu of available Catalyst Center hosts:

    choice set

  • Custom Field 2 is called ccc_device_id, and is a Text type field that maps to the device UUID in the Cisco Catalyst Center controller

    device ID

  1. Devices managed by the Cisco Catalyst Center are added to NetBox and the device data includes the custom field values:

    netbox device

  2. The NetBox Inventory Plugin for Ansible is used to dynamically generate the inventory from NetBox to be used in the Ansible playbook:

    # ansible.cfg
    
    [defaults]
    inventory = ./netbox_inv.yml
    
    # netbox_inv.yml
    
    plugin: netbox.netbox.nb_inventory
    validate_certs: False
    group_by: 
     - device_roles
     - sites
    
  3. The Ansible playbooks target hosts based on the device_roles as defined in NetBox and pulled from the dynamic inventory. They contain a set_facts task to map the values of the ccc_device_id and cisco_catalyst_center custom fields to the devices, so they can be used in later tasks per inventory device:

    ---
    - name: Get Device Details From Cisco Catalyst Center
      hosts: device_roles_distribution, device_roles_access
    
    tasks:
        - name: Set Custom Fields as Facts for Cisco Catalyst Center host and Device UUID
        set_fact:
            cisco_catalyst_center: "{{ hostvars[inventory_hostname].custom_fields['cisco_catalyst_center'] }}"
            ccc_device_id: "{{ hostvars[inventory_hostname].custom_fields['ccc_device_id'] }}"
    
    - name: Get Device Details
      uri:
        url: "https://{{ cisco_catalyst_center }}/dna/intent/api/v1/network-device/{{ ccc_device_id }}"
        method: GET
        return_content: yes
        validate_certs: no
        headers:
          Content-Type: "application/json"
          x-auth-token: "{{ login_response.json['Token'] }}"
      register: device_details
      delegate_to: localhost
    

Getting Started with the Ansible Playbooks

  1. Clone the Git repo and change into the netbox-ansible-cisco-cc directory:
    git clone https://github.com/netboxlabs/netbox-ansible-cisco-cc.git
    cd netbox-ansible-cisco-cc
    
  2. Create and activate Python 3 virtual environment:
    python3 -m venv ./venv
    source venv/bin/activate
    
  3. Install required Python packages:
    pip install -r requirements.txt
    
  4. Set environment variables for the NetBox API token and URL:
    export NETBOX_API=<YOUR_NETBOX_URL> (note - must include http:// or https://) 
    export NETBOX_TOKEN=<YOUR_NETBOX_API_TOKEN>
    
  5. List the devices and host variables retrieved from NetBox using the dynamic inventory:
    ansible-inventory -i netbox_inv.yml --list
    
  6. Note how the Custom Fields ccc_device_id and cisco_catalyst_center and their values are retrieved for each device:
    "sw4": {
        "ansible_host": "10.10.20.178",
        "custom_fields": {
            "ccc_device_id": "826bc2f3-bf3f-465b-ad2e-e5701ff7a46c",
            "cisco_catalyst_center": "sandboxdnac.cisco.com"
        },
    
  7. Run a playbook making sure to specify the NetBox dynamic inventory with the -i flag. For example:
    ansible-playbook -i netbox_inv.yml get_device_details.yml
    
  8. When you have finished working you can deactivate the Python virtual environment:
    deactivate
    

References

netbox-ansible-cisco-cc's People

Contributors

richbibby avatar dependabot[bot] avatar natm avatar

Stargazers

Misagh Momeni Bashusqeh avatar

Forkers

tomczyzewski

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.