Ansible-Access Network via Netconf

Posted on October 11, 2018

Continue to try ansible with the device which was configure in netconf feature on Cisco IOS/IOSXE.

Ansible Inventory:

---
netconf:
hosts:
    netconfIos:
    ansible_host: "172.16.254.100"
    ansible_network_os: "ios"
    ansible_ssh_port: 22
    netconfJunos:
    ansible_host: "172.16.254.9"
    ansible_network_os: "junos"
    ansible_ssh_port: 830
vars:
    ansible_connection: "netconf"
    ansible_ssh_user: test
    ansible_ssh_pass: test123

Note:

  1. ansible_connnection should be ‘netconf’
  2. Be careful on the netconf port, it should be 22 if you enable netconf over SSH (the default port is 830)

PlayBook:

- name: IOS
hosts: netconfIos
gather_facts: false
tasks:
    - name: Get config for IOS devices
    netconf_get:
        source: running
    register: iosnetconf

    - name: Display output
    debug:
        msg: "{{ iosnetconf.stdout }}"

Note:

  1. I tried module: ios_facts with the error:

    fatal: [netconfIos]: FAILED! => {“changed” : false, “msg”: “Connection type netconf is not valid for this module”}.
    

    This is why I choose netconf_get.

    BTW: I tried the module: junos_facts on Juniper device, works.

  2. With return values of netconf_get module and Register variables of Ansible, you can verify the output of netconf request.

Run PlayBook

ansible-playbook -i inventory_netconf.yml pb_netconf.yml
netconf
netconf

Ansible-Access Network via Netconf


donation

Scan the QR code using WeChat

comments powered by Disqus