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:
- ansible_connnection should be ‘netconf’
- 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:
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.
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
Scan the QR code using WeChat