Skip to content

Instantly share code, notes, and snippets.

@jabelk
Last active September 3, 2020 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jabelk/8b7949ae3c983f7f38fd456a345e7602 to your computer and use it in GitHub Desktop.
Save jabelk/8b7949ae3c983f7f38fd456a345e7602 to your computer and use it in GitHub Desktop.
CLI done to configure and then check output in YAML with ansible, then revert to send actual request:
developer@ncs(config)# services nso-snmp mytest_ro123 device dist-rtr01
developer@ncs(config-nso-snmp-mytest_ro123)# commit
Commit complete.
developer@ncs(config-nso-snmp-mytest_ro123)# no services nso-snmp mytest_ro123 device dist-rtr01
developer@ncs(config-nso-snmp-mytest_ro123)# commit
Commit complete.
---
- name: Some NSO fun
hosts: localhost
gather_facts: no
vars:
username: "developer"
password: "C1sco12345"
url: "https://10.10.20.49:443/jsonrpc"
perform_backup: no
tasks:
- name: Check all sync
nso_show:
username: "{{ username }}"
password: "{{ password }}"
url: "{{ url }}"
path: /ncs:services/
# operational: true
changed_when: False
register: r_sync
- debug:
var: r_sync
Output:
(py3venv) [developer@devbox nw-demo]$ ansible-playbook nso_demo/nso_show.yml
[WARNING]: Unable to parse /home/student1/networking-workshop/lab_inventory/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [Some NSO fun] ****************************************************************************************************************************************************
TASK [Check all sync] **************************************************************************************************************************************************
ok: [localhost]
TASK [debug] ***********************************************************************************************************************************************************
ok: [localhost] =>
r_sync:
changed: false
failed: false
output:
data:
tailf-ncs:services:
logging:
logger:
- log-entry-level: info
name: default
nso-snmp:nso-snmp:
- device:
- dist-rtr01
snmp_ro: mytest_ro123
Taking that output into a playbook snioppet
Playbook:
---
- name: Configure NSO from Ansible
hosts: localhost
gather_facts: no
vars:
username: "developer"
password: "C1sco12345"
url: "https://10.10.20.49:443/jsonrpc"
perform_backup: no
tasks:
- name: Add a new SNMP RO community string
nso_config:
username: "{{ username }}"
password: "{{ password }}"
url: "{{ url }}"
data:
tailf-ncs:services:
nso-snmp:nso-snmp:
- device:
- dist-rtr01
snmp_ro: mytest_ro123
changed_when: False
register: r_sync
- debug:
var: r_sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment