Giter Club home page Giter Club logo

ansible-netconf-openconfig-demo's Introduction

Introduction

This repo contains the code to configure the following devices via Ansible:

  • QFX - via NETCONF and YANG OpenConfig models.
  • IOSL2 - via native network modules (i.e ios_vlan)

The key benfit of this demo is to abstract the required Ansible code needed to program NETCONF based devices via the use of OpenConfig YANG models.

Note: The steps for installating OC within JunOS can be found at : https://www.juniper.net/documentation/en_US/junos/topics/task/installation/openconfig-installing.html

Ansible

Below is Ansible folder/file structure.

.
|-- ansible.cfg
|-- inventory
|   `-- hosts
|-- playbooks
|   |-- group_vars
|   |   `-- all.yaml
|   |-- host_vars
|   |   |-- ios1.yml
|   |   `-- qfx1.yml
|   |-- master.yml
|   |-- native.yml
|   `-- netconf.yml
`-- scripts
    `-- convert.py

The inventory child groups define which hosts are run against which playbook. Shown below:

[junos:vars]
ansible_network_os=junos
ansible_user=admin
ansible_password=Juniper

[ios:vars]
ansible_network_os=ios
ansible_user=cisco
ansible_ssh_pass=cisco
ansible_connection=network_cli

[junos]
qfx1 ansible_host=172.29.133.2

[ios]
ios1 ansible_host=172.29.133.3

[native:children]
ios

[netconf:children]
junos

The netconf.yml playbook converts the host_vars file into an XML based YANG model via a custom script scripts/convert.py. There is a potential you could look to use the yang ansible role. However, testing on this seems limited. However, as a next step I would recommend testing this role as it could "potentially" simplfy the code base down even further.

To run the plays to configure both devices via native and NETCONF methods run the command. The master playbook contains both the native.yml and netconf.yml playbooks.

cd ansible
ansible-playbook -i inventory/hosts playbooks/master.yml

OpenConfig

To print an ASCII representation of the YANG model, use the following command:

pyang -f tree oc-models/vlan/openconfig-vlan.yang -p oc-models/

The different representations of the models can be located within data. For the YAML representation please refer to the ansible host_vars.

data
├── yang.json
└── yang.xml

To convert an OC based YANG model to YAML, I found the easiest way was to use JunOS to print the model as JSON, like so:

lab@fabric-01> show configuration openconfig-bgp:bgp | display json
{
    "openconfig-bgp:bgp" : {
        "neighbors" : {
            "neighbor" : [
            {
                "neighbor-address" : "192.168.1.2",
                "config" : {
                    "peer-as" : 110,
                    "peer-group" : "OC"
                }
            }
            ]
        },
        "peer-groups" : {
            "peer-group" : [
            {
                "peer-group-name" : "OC",
                "config" : {
                    "local-as" : 104,
                    "peer-type" : "EXTERNAL"
                },
                "apply-policy" : {
                    "config" : {
                        "import-policy" : ["bgp-in"],
                        "export-policy" : ["bgp-out"]
                    }
                }
            }
            ]
        }
    }
}

Then use a JSON to YAML convertor to get the data into the required YAML representation.

## Makefile
The included Makefile provides the following options:

make

add-venv-py2.7 Install virtualenv, create virtualenv, install requirements add-venv-py3.6 Install virtualenv, create virtualenv, install requirements install-py3.6 Install Python3.6 lint Remove YAML EOL spaces, perform yaml and py linting. py-lint Perform linting against py files remove-yml-eol-spaces Remove end of line spaces from yaml files yaml-lint Perform linting against ansible yaml files

ansible-netconf-openconfig-demo's People

Contributors

rickdonato avatar

Watchers

 avatar

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.