Ansible on Fedora
The goal of this post is to describe the steps needed to install and configure Ansible to connect to a Nokia 7×50 via NETCONF.
I’ve just installed an empty Fedora server and configured the network interfaces.
Installation of Ansible is pretty straightforward, just use yum:
Check which version:
[larsg@fc-server ~]$ ansible --version
ansible 2.5.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/larsg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15 (default, May 16 2018, 17:50:09) [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)]
I then add some entries in the hosts file to be able to use the names instead of IP’s.
For Ansible to connect to the SRs we need the host key saved in ~/.ssh/known_hosts. The easiest way to do this is to connect to the device using SSH and answering yes to saving the host key.[larsg@fc-server ansible]$ ssh r1
The authenticity of host 'r1 (10.23.16.41)' can't be established.
RSA key fingerprint is SHA256:kdE6JrRgpflIzPW6R67/lBGkWLYW7e9mRiGPWOejDO0.
RSA key fingerprint is MD5:98:f5:24:1e:b0:16:eb:00:00:69:4c:9c:b4:3e:ee:ca.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'r1,10.23.16.41' (RSA) to the list of known hosts.'
An exception occurred during task execution. To see the full traceback, use -vvv.
The error was: SSHUnknownHostError: Unknown host key [98:f5:24:1e:b0:16:eb:00:00:69:4c:9c:b4:3e:ee:ca] for [r1]
fatal: [r1]: FAILED! > {"changed": false, "msg": "error connecting to the device: Unknown host key [98:f5:24:1e:b0:16:eb:00:00:69:4c:9c:b4:3e:ee:ca] for [r1]"}
to retry, use: --limit @/home/larsg/ansible/fil1.retry
The SR also needs to be configured to allow NETCONF, below is the minimum configuration needed:
configure system security profile "administrative" netconf base-op-authorization lock
configure system security user admin access netconf
configure system netconf no shutdown
[larsg@fc-server ansible]$ cat nokia-01.yml
---
- hosts: r1
gather_facts: no
connection: local
tasks:
- name: READ PARAMETERS
include_vars:
file: nodes/{{ inventory_hostname }}.yml
- name: NETCONF TEST
netconf_config:
host: "{{ inventory_hostname }}"
username: admin
password: admin
datastore: running
xml: |
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<configure xmlns="urn:alcatel-lucent.com:sros:ns:yang:conf-r13">
<system>
<name>
<system-name>{{ global_var.system_name }}</system-name>
</name>
</system>
</configure>
</config>
...
Now it’s time to run this very simple playbook and see what happens.
[larsg@fc-server ansible]$ ansible-playbook nokia-01.yml
PLAY [r1] *********************************************************************************
TASK [READ PARAMETERS] ********************************************************************
ok: [r1]
TASK [NETCONF TEST] ***********************************************************************
changed: [r1]
PLAY RECAP ********************************************************************************
r1 : ok=2 changed=1 unreachable=0 failed=0
To see more detailed output, add a couple of -v ‘s to ansible-playbook command.
[larsg@fc-server ansible]$ ansible-playbook nokia-01.yml -vvv
ansible-playbook 2.5.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/larsg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.15 (default, May 16 2018, 17:50:09) [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin
PLAYBOOK: nokia-01.yml ************************************************************************
1 plays in nokia-01.yml
PLAY [r1] *************************************************************************************
META: ran handlers
TASK [READ PARAMETERS] ************************************************************************
task path: /home/larsg/ansible/nokia-01.yml:8
ok: [r1] => {
"ansible_facts": {
"global_var": {
"system_name": "r1"
}
},
"ansible_included_var_files": [
"/home/larsg/ansible/nodes/r1.yml"
],
"changed": false
}
TASK [NETCONF TEST] ***************************************************************************
task path: /home/larsg/ansible/nokia-01.yml:12
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/netconf/netconf_config.py
<r1> ESTABLISH LOCAL CONNECTION FOR USER: larsg
<-snip>
changed: [r1] => {
"changed": true,
"invocation": {
"module_args": {
"allow_agent": true,
"datastore": "running",
"host": "r1",
"hostkey_verify": true,
"look_for_keys": true,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 830,
"save": false,
"src": null,
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n
<configure xmlns=\"urn:alcatel-lucent.com:sros:ns:yang:conf-r13\">\n <system>\n <name>\n <system-name>r1
</system-name>\n </name> \n </system>\n </configure>\n </config>\n"
}
},
"server_capabilities": [
"urn:alcatel-lucent.com:sros:ns:yang:conf-ifgrphandler-r13?module=alu-conf-ifgrphandler-r13&revision=2014-10-20",
<cut some output>
]
}
META: ran handlers
META: ran handlers
PLAY RECAP **********************************************************************************
r1 : ok=2 changed=1 unreachable=0 failed=0
TASK [NETCONF TEST] **************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv.
The error was: Writing to or reading from candidate datastore not supported in the specified namespace
fatal: [r1]: FAILED! => {"changed": false, "msg": "error editing configuration: \n Writing to or reading from candidate datastore not supported in the specified namespace\n "}
to retry, use: --limit @/home/larsg/ansible/nokia-01.retry