Devnet
NetDevOps
Ansible

Ansible Overview

Ansible, acquired by RedHat in 2015, is a potent open-source automation tool widely used in NetDevOps. It offers simplicity, an agentless architecture, and cross-platform support. NetDevOps utilizes Ansible for automating network tasks and managing configurations. Unlike orchestration tools like Cisco Network Services Orchestrator (NSO), Ansible serves as a configuration management tool.

Configuration Management vs. Orchestration

Configuration management handles configurations, while orchestration coordinates and manages systems to maintain desired states. Configuration management targets individual devices, whereas orchestration deals with system-level management. For instance, configuring a router's OSPF settings exemplifies configuration management, while orchestrating the setup of a VM in a specific network involves multiple systems.

Ansible Playbooks and Modules

Ansible employs playbooks, written in YAML, to guide tasks execution. Modules, Python-based libraries, communicate with devices/systems. Each module includes key-value pairs instructing actions. Ansible supports various built-in and community-created modules, facilitating customization.

When Ansible integrates with Cisco NSO, it leverages the strengths of both tools. Ansible manages workflows and multi-domain environments, while NSO provides a unified network API, transaction management, and rollback capabilities.

ModuleDescription
nso_actionExecutes Cisco NSO actions, ensuring expected outputs.
nso_configManages configurations in Cisco NSO and verifies service states.

Ansible nso_action Module

The nso_action module executes NSO actions and verifies outcomes. Key parameters include action parameters, NSO credentials, action path, and JSON-RPC URL.

Ansible nso_action Module Example

- name: PUSH CONFIGS TO DEVICES WITH NSO_CONFIG
  hosts: "CSR1"
  gather_facts: no
  tasks:     
    - name: ENSURE DEVICE IS IN SYNC
      nso_action:
        url: http://CSR1:8080/jsonrpc
        username: "{{ ansible_user }}"
        password: "{{ ansible_password }}"
        path: /ncs:devices/device{"{{ item }}"}/sync-to
      with_items:
        - R1
        - R2
        - R3

Ansible nso_config Module

The nso_config module manages configurations in Cisco NSO and verifies service synchronization.

Ansible nso_config Module Example

- name: LOAD CONFIG
  include_vars:
    file: "vars/{{ item }}.yaml"
    name: "{{ item }}_config"
  loop:
    - R1
    - R2
    - R3
 
- name: PUSH CONFIG TO DEVICE
  nso_config:
    url: http://CSR1:8080/jsonrpc
    username: "{{ ansible_user }}"
    password: "{{ ansible_password }}"
    data: "{{ item }}"  
  loop:
    - "{{ R1_config }}"
    - "{{ R2_config }}"
    - "{{ R3_config }}" 

In this example, configurations from YAML files are loaded and pushed to corresponding routers using the nso_config module.

These modules facilitate seamless integration between Ansible and Cisco NSO for efficient network management.