Scrapli_netconf is a winner ??

Scrapli_netconf is a winner ??

I have just uploaded couple of netconf/restconf scripts for updating the NTP configuration for nxos using system yang data model.

I recently had a hard time to get my scripts/playbooks working for nxos version 7.0(x), I have tried the following but none of them worked for this version of nxos, however it works fine with 9.x versions

  • Ansible Netconf module
  • netconf-console cli
  • ncclient Library for Netconf

After spending couple of days and trying to automate via above tools with no luck whatsoever, I had a second thought to use scrapli_netconf as I used scrapli to automate traditional style network configuration changes but I never used it for Netconf and guess what, as soon as I wrote my first simple script to set the ntp desired state configuration for this version of nxos, apparently it worked straight away and it did really put the smile on my face, like this --> ??

I was so impressed and I really want to use scrapli_netconf moving forward, more likely with the Ansible, I may either have to write a module with scrapli or at least will raise it as feature enhancement with Ansible community to create one using scrapli_netconf, there is also an extension of scrapli_netconf for nornir framkework which works really well too.

I do not know the exact reason why all of above are not working for this version of nxos as I did not go deep to find out the cause of failure but I know one thing that they all are failing, because they all use ncclient library. I am not against ncclient library as it is very popular tool and works really great, however it failed for this nxos version and I will be raising an issue on github, I have already raised one for Ansible Netconf module though.

I like to thank @Carl Montanari for this awesome library and really keen to know what magic you did to make this work :) I also like to thank @John McGovern for his one of the videos for setting the EIGRP and NTP desired state configuration which inspired me to write these scripts.

Finally, I would like to mention few caveats I encountered whilst writing these basic scripts.

  • NXOS uses system yang data model like we have native data models in IOSXE and XR
  • NXOS only supports subtree filter not xpath unlike IOSXE at the time of writing this article.
  • ?Restconf for nxos uses dot notation rather than hyphen to define headers e.g. “application/yang.data+json”, even though hyphen works but it will give you the output in xml format not json.
  • ?ncclient works great when I used difflib for configuration comparison before and after, however I had to use regular expression for scrapli_netconf to strip the rpc-reply tags as they cause the changes.
  • In scrapli, you don't have to define filter tag, however, ncclient requires filter tag.
  • Scrapli does not play well with Windows but works really great with Linux systems.

Here is the github link for the code, feel to free to try and let me know how they work for you.

https://github.com/muhammad-rafi/Python3_Network_Automation/tree/main/netconf_scripts

Thanks,

- Rafi?

ncclient script output
scrapli_netconf script output


John McGovern

Network Automation Instructor

3 年

Great job, Muhammad! Love me some Scrapli :)

要查看或添加评论,请登录

Muhammad Rafi的更多文章

  • no Restconf, no Netconf only napalm

    no Restconf, no Netconf only napalm

    Following my last post regarding the nxos interface table, I have built another script for IOS/IOXE devices to pull…

    2 条评论

社区洞察

其他会员也浏览了