02-21-2020 05:56 AM
Hi,
how can I delete a device from a group using the jsonrpc or the Ansible-module "nso_config" to be exact?
I was able to delete other configuration, like devices using the "__state: absent"-statement but this is not working for devices in groups.
In other words im looking for an API-equivalent for:
delete devices device-group somegroup device-name somedevice
How would the API-Call / yaml for nso_config look like?
We are using NSO 5.3.
Thanks a lot.
07-02-2020 07:01 AM
Bump as I stil have no solution.
07-02-2020 01:29 PM
I will admit that I am not at all an expert on this, but it ought to work, what error do you get?
07-02-2020 11:55 PM
Hi,
thanks for your reply. I have the following group in NSO:
user@ncs% show devices device-group somegroup device-name [ test-mb ];
I want to remove "test-mb" from the group via REST-API / jsonrpc using the Ansible-module nso_config.
I'll post my approaches with error messages later on.
07-03-2020 02:28 AM - edited 07-03-2020 02:30 AM
Minimum example:
This works (deleting a whole group):
--- - hosts: all connection: local gather_facts: no environment: http_proxy: '' https_proxy: '' vars_files: - ../roles/nso_import/vars/main.yml tasks: - name: Add devices to Cisco NSO nso_config: url: "{{ nso_config.protocol }}://{{ ansible_host }}:{{ nso_config.api_port }}/{{ nso_config.endpoint }}" username: "{{ nso_config.username }}" password: "{{ nso_config.password }}" validate_certs: "{{ nso_config.validate }}" timeout: "{{ nso_config.timeout }}" data: tailf-ncs:devices: device-group: - name: somegroup2 __state: absent
This does not work (deleting a single element of the group):
--- - hosts: all connection: local gather_facts: no environment: http_proxy: '' https_proxy: '' vars_files: - ../roles/nso_import/vars/main.yml tasks: - name: Add devices to Cisco NSO nso_config: url: "{{ nso_config.protocol }}://{{ ansible_host }}:{{ nso_config.api_port }}/{{ nso_config.endpoint }}" username: "{{ nso_config.username }}" password: "{{ nso_config.password }}" validate_certs: "{{ nso_config.validate }}" timeout: "{{ nso_config.timeout }}" data: tailf-ncs:devices: device-group: - name: somegroup test-mb: __state: absent #################################################### fatal: [stnnso1]: FAILED! => {"changed": false, "msg": "no child in /ncs:devices/device-group{somegroup} with name test-mb. children ncs:name,ncs:location,ncs:device-name,ncs:device-group,ncs:member,ncs:ned-id,al:alarm-summary,ncs:connect,ncs:sync-to,ncs:sync-from,ncs:check-sync,ncs:check-yang-modules,ncs:fetch-ssh-host-keys,ncs:apply-template"}
Thanks for your help!
07-03-2020 03:06 AM
Minimal example:
--- - hosts: all connection: local gather_facts: no environment: http_proxy: '' https_proxy: '' vars_files: - ../roles/nso_import/vars/main.yml tasks: - name: Delete from a group nso_config: url: "{{ nso_config.protocol }}://{{ ansible_host }}:{{ nso_config.api_port }}/{{ nso_config.endpoint }}" username: "{{ nso_config.username }}" password: "{{ nso_config.password }}" validate_certs: "{{ nso_config.validate }}" timeout: "{{ nso_config.timeout }}" data: tailf-ncs:devices: device-group: - name: somegroup test-mb: __state: absent
Error:
fatal: [nso]: FAILED! => {"changed": false, "msg": "no child in /ncs:devices/device-group{somegroup} with name test-mb. children ncs:name,ncs:location,ncs:device-name,ncs:device-group,ncs:member,ncs:ned-id,al:alarm-summary,ncs:connect,ncs:sync-to,ncs:sync-from,ncs:check-sync,ncs:check-yang-modules,ncs:fetch-ssh-host-keys,ncs:apply-template"}
Any idea what I'm doing wrong. Thanks!
07-06-2020 10:33 AM - edited 07-06-2020 10:42 AM
Haven't tested it myself, but according to the error it's expecting one more child. Try "device-name"
data: tailf-ncs:devices: device-group: - name: somegroup device-name: - test-mb
__state:absent
07-06-2020 10:45 PM
Hi, thanks for your answer.
I don't get an error with your syntax but unfortunately the host is not deleted from the group. Ansible detects no change, "test-mb" remains in "somegroup" in NSO.
ansible-playbook -i stnnso1.nso.telekom.de, test.yml PLAY [all] ******************************************************************************************************************************************************************************************************************************************* TASK [Delete from a group] *************************************************************************************************************************************************************************************************************************** ok: [nso] PLAY RECAP ******************************************************************************************************************************************************************************************************************************************* stnnso1.nso.telekom.de : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Any other hints what I could try out?
07-07-2020 05:23 AM - edited 07-07-2020 05:25 AM
Just had a chance to try it out. I have two XE netsims and two XR netsims. I added XE0 to the device group. If I try to remove it, nothing happens. If I modify the group and add XE1 with a "__state: absent" in there, then it removes XE0. If I go back and replace it with XE1, it removes XE0. So basically what seems to be happening is that whatever is in the list is left. And if it's not in the list it's removed.
State of device group:
admin@ncs# show running-config devices device-group somegroup devices device-group somegroup device-name [ xe0 xe1 xr0 xr1 ] !
Play:
- name: Delete a device from a group nso_config: url: "{{ api.url }}" username: "{{ api.username }}" password: "{{ api.password }}" data: tailf-ncs:devices: device-group: - name: somegroup device-name: - xe0 __state: absent
Result:
admin@ncs# show running-config devices device-group somegroup devices device-group somegroup device-name [ xe0 ] !
So it looks like whatever is in the leaf-list "device-name" is left, and anything that is absent from the list is removed. Seems to me this is the opposite behavior then expected. Bug??
More data:
Before:
admin@ncs# show running-config devices device-group somegroup devices device-group somegroup device-name [ xe0 xe1 xr0 xr1 ] !
Play:
- name: Delete a device from a group nso_config: url: "{{ api.url }}" username: "{{ api.username }}" password: "{{ api.password }}" data: tailf-ncs:devices: device-group: - name: somegroup device-name: - xr0 - xr1 __state: absent
Result:
admin@ncs# show running-config devices device-group somegroup devices device-group somegroup device-name [ xr0 xr1 ] !
07-07-2020 05:44 AM
Thank you for your effort and validating my results!
I know that the nso_* Ansible-modules were contributed by Cisco. Are they still maintained? Who could look into it and possible provide a patch that could be included in one of the next Ansible-versions?
07-07-2020 03:08 AM
I believe the issue is that you are dealing with a leaf-list and not a list.
Can you check that your ansible version is larger than 2.6 per this commit?:
https://github.com/ansible/ansible/pull/36583
07-07-2020 04:03 AM
Hi,
Ansible is brand-new:
# ansible --version ansible 2.9.10 config file = /var/www/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]
Is @cnasten still maintaining the module?
10-07-2020 12:18 PM
__state must be indented under the key of the list item you wish to remove.
Ansible reports "ok" with nothing changed:
- xr1 __state: absent
Ansible reports "modified" and item is deleted:
- xr1 __state: absent
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide