cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
877
Views
0
Helpful
2
Replies

RESTCONF with Ansible to check-sync and/or sync-from

valeluia
Level 1
Level 1

Is it possible to create an NSO action to check sync status, similar with the example below, but with RESTCONF while using Ansible

 

nso_action:
url: "{{ nso.url }}"
username: "{{ nso.username }}"
password: "{{ nso.password }}"
path: "/ncs:devices/device{ {{ item.device }} }/check-sync"
input: {}
register: result

 

2 Replies 2

valeluia
Level 1
Level 1

The configuration that I have tried in ansible:

---
- name: Check-sync
hosts: localhost
connection: httpapi
gather_facts: no

vars:
ansible_connection: "httpapi"
ansible_network_os: "restconf"
ansible_httpapi_use_ssl: false
ansible_httpapi_validate_certs: false
ansible_httpapi_port: 8080
ansible_httpapi_restconf_root: "/restconf/operations/" # default
ansible_user: "admin"
ansible_password: "admin"
check_sync: "ncs:check-sync"

tasks:
- name: "config"
ansible.netcommon.restconf_config:
path: "tailf-ncs:devices/device=R11"
content: "{{ check_sync|to_nice_json}}"
register: restconf_result

Result: fatal: [localhost]: FAILED! => {"changed": false, "code": 405, "msg": "HTTP Error 405: Method Not Allowed"}

I'm able to run it manually:

$ curl -u admin:admin http://localhost:8080/restconf/operations/tailf-ncs:devices/device=R11/check-sync -X POST -H 'Accept: application/yang-data+json' -H 'Content-Type: application/yang-data+json'
{
"tailf-ncs:output": {
"result": "out-of-sync",
"info": "got: 2023-09-02 10:11:14 CEST expected: 2023-09-01 13:52:38 CEST\n"
}
}

Any suggestion?

 

 

valeluia
Level 1
Level 1

Alternative found:

 

 tasks:
- name: "check sync status"
uri:
url: http://localhost:8080/restconf/operations/tailf-ncs:devices/device=R11/check-sync
url_username: admin
url_password: admin
method: POST
headers:
Content-Type: application/yang-data+json
register: result