Skip to content

Commit ad78f4f

Browse files
author
Adisorn Ermongkonchai
committed
updated all modules to work with Ansible 2.5 and moved old version to ansible-2.3 branch
1 parent 6c8b6c2 commit ad78f4f

File tree

152 files changed

+7655
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+7655
-49
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 301 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,318 @@
1-
Ansible Test Setup
2-
==================
1+
# Introduction to IOS-XR Ansible
32

4-
- Create 2 XRV9K (Sunstone) VMs and 1 Linux server on MB Cloud following
5-
the instruction in the link below
6-
* http://tc-midnight.cisco.com:8080/wiki/MB%20Cloud%20XR
3+
In the nutshell, Ansible is an automation tool for configuring system,
4+
deploying software, and orchestrating services. Unlike Puppet and Chef which
5+
is an agent-based architecture, Ansible does not require daemon running or
6+
agent pre-installed on the target nodes to interact with a server.
7+
Ansible could be specified to run either on a local server or on a remote
8+
node.
79

8-
NOTE:
9-
The nightly build images provided on the MB Cloud is based on xr-dev.
10-
Unfortunately, the missing Python libraries were committed to r60y
11-
(CSCux90222). These missing libraries are required for Ansible to run
12-
in "remote" mode. The tests that were exercising here run on "local" mode
10+
The different between local and remote connection mode in Ansible is basically
11+
where the script (so-called Ansible module) is being run. For the **remote**
12+
mode, Ansible automatically attempts to establish SSH connection to the remote
13+
node. Once established, it transfers the script and runs it on the remote node.
14+
The script responds to the server in JSON formatted text. This mode requires
15+
setting up third-party namespace (TPNNS) on the IOS-XR node.
1316

14-
- You will also need k9sec security package to be installed in your XRV9K VMs.
15-
Using the following example command to install the k9sec pacakge.
16-
* install update source tftp://192.168.1.1 xrv9k-iosxr-security-1.0.0.0-r60125I
17-
* show install active
17+
As for the **local** mode, Ansible run the module script on the local server.
18+
The script has to establish a connection to the remote node itself. The
19+
local mode module uses Ansible network module to establish SSH connection
20+
to the IOS-XR console to run CLI command.
1821

19-
- Pull YDK from the gitlab.cisco.com into the Linux server created
20-
* git clone [email protected]:ydk-dev/ydk-py.git
22+
There are 6 different ways to access IOS-XR in local mode.
2123

22-
- Pull Ansible Core modules
24+
1. **Console CLI** - connect to IOS-XR console through SSH port 22 and use
25+
CLI commands.
26+
2. **TPNNS CLI** - connect to IOS-XR Linux shell through SSH port 57722
27+
and use helper programs, /pkg/bin/xr_cli or /pkg/sbin/config.
28+
3. **Raw XML** - connect to IOS-XR console through SSH port 22 to exchange XML
29+
construct with IOS-XR xml agent.
30+
4. **Raw NETCONF 1.0** - connect to IOS-XR console through SSH port 22 to
31+
exchange NETCONF 1.0 XML construct with IOS-XR netconf agent.
32+
5. **Raw NETCONF 1.1** - connect to IOS-XR console through SSH port 830 to
33+
exchange NETCONF 1.1 XML construct with IOS-XR netconf-yang
34+
agent.
35+
6. **YDK NETCONF** - use the Cisco YDK API service to manage IOS-XR device
36+
through SSH port 830.
37+
38+
Managing the IOS-XR device in the remote mode required TPNNS through SSH
39+
port 57722 with the helper programs, /pkg/bin/xr_cli and /pkg/sbin/config, to
40+
deliver CLI commands and configuration to the IOS-XR, respectively. This
41+
remote mode connection is identical to TPNNS CLI running in local mode except
42+
for how the SSH connection is being established and where the script is run.
43+
44+
# Understand connection variants
45+
With different variants for local and remote modes mentioned earlier, before
46+
implementing Ansible modules, one needs to be aware of their limitation.
47+
48+
**Linux-based vs. QNX-based IOS-XR**
49+
50+
* QNX-based IOS-XR can only run in local mode
51+
* Earlier version of Linux-based IOS-XR also can only run in local mode due
52+
to incomplete Python libraries
53+
* Linux-based IOS-XR (eXR 6.0.2 or later) can run both remote and local modes
54+
55+
**CLI vs. XML/NETCONF**
56+
57+
* With CLI mode, you can do all CLI commands as you would do interactively.
58+
* The XML/NETCONF mode allows you to use Cisco XML or NETCONF commands in XML
59+
construct to configure IOS-XR.
60+
61+
**Console CLI vs. TPNNS CLI**
62+
63+
* Console CLI allows you to do all CLI commands as you would do interactively.
64+
* TPNNS CLI can either be implemented in local or remote mode. It connects
65+
to IOS-XR Linux shell and requires helper programs, /pkg/bin/xr_cli or
66+
/pkg/sbin/config, to deliver CLI commands or configure IOS-XR, respectively.
67+
Currently, "commit replace" is not supported by /pkg/sbin/config.
68+
69+
**Raw XML/NETCONF vs. YDK NETCONF**
70+
71+
* Raw NETCONF mode allows you to configure IOS-XR using NETCONF commands in
72+
RPC XML construct through standard SSH port 22 with termination sequence
73+
**]]>]]>** and port 830 with **##** termination sequence. The response is
74+
also in RPC XML construct.
75+
* Alternatively, you can use YDK python API to configure IOS-XR through SSH
76+
port 830. The API automatically generates the RPC XML construct based on
77+
the YANG model provided.
78+
79+
**NOTE:** IOS-XR NETCONF 1.1 XML construct is based on Cisco IOS-XR YANG model
80+
which is currently limited, e.g. it doesn’t support SMU package
81+
installation. Although limited, the Cisco IOS-XR YANG definitions will
82+
continue to grow as more definitions are added and would be a preferred
83+
method for accessing IOS-XR.
84+
85+
# Dependencies
86+
87+
- manageability (mgbl) and security (k9sec) packages are required on IOS-XR.
88+
89+
- Pull YDK from the github onto a Linux server
90+
* git clone https://github.com/CiscoDevNet/ydk-py
91+
92+
- Pull Ansible Core modules onto a Linux server
2393
* git clone git://github.com/ansible/ansible.git --recursive
2494

25-
Addition read on Ansible installation is here
95+
Additional read on Ansible installation is here
2696
* http://docs.ansible.com/ansible/intro_installation.html#getting-ansible
2797

28-
Running Ansible
29-
===============
98+
# Directories structure
3099

31-
- Edit and source Ansible, YDK, and Python environment to point to your
32-
installed applications
33-
* cd iosxr/local
34-
* vi ansible_env
35-
* source ansible_env
100+
```
101+
iosxr-ansible
102+
├── config
103+
├── local
104+
│   ├── common
105+
│   ├── library
106+
│   └── samples
107+
│   ├── cli
108+
│   ├── tpnns
109+
│   ├── xml
110+
│   └── ydk
111+
└── remote
112+
├── library
113+
└── samples
114+
└── install
36115
37-
- Edit "ansible_hosts" file to change "ss-xr" host IP to your 2 XRV9K VMs
116+
Directory Description
117+
118+
config Contains sample IOS-XR configuration files
119+
local/library Contains Ansible modules for local mode
120+
local/samples/cli Contains sample playbooks using Console CLI
121+
local/samples/tpnns Contains sample playbooks using TPNNS access method
122+
local/samples/xml Contains sample RPC XML used with iosxr_netconf_send
123+
local/samples/ydk Contains sample playbooks using YDK API's
124+
local/common Contains IOS-XR common Python functions
125+
remote/library Contains Ansible modules for remote mode
126+
remote/samples Contains sample playbooks using Namespace Shell CLI
127+
remote/samples/install Contains additional playbooks showing direct access
128+
to IOS-XR using shell
129+
```
38130

39-
- Create default crypto key in your XRV9K VMs (select default 1024 bits)
40-
* crypto key generate rsa
41-
* show crypto key mypubkey rsa
131+
# IOS-XR setup
42132

133+
NOTE: Some of these instruction may require root access for setting IOS-XR.
134+
135+
- Create default crypto key on your XRV9K VMs (select default 2048 bits)
136+
137+
```
138+
RP/0/RP0/CPU0:ios# crypto key generate rsa
139+
RP/0/RP0/CPU0:ios# show crypto key mypubkey rsa
140+
```
43141
- Configure IOS-XR as shown in ss1.cfg and ss2.cfg for both XRV9K VMs.
44142
Make any necessary changes, such as, management IP address and hostname
45143
Here are required configuration
46-
* ssh server v2
47-
* ssh server netconf vrf default
48-
* ssh server logging
49-
* xml agent ssl
50-
* netconf agent tty
51-
* netconf-yang agent ssh
52-
53-
- Make sure you can connect to both XRV9K VMs management port
54-
55-
* ssh [email protected] "show run"
56-
57-
NOTE:
58-
Currently, crypto key import is not working (CSCuy80921) so when
59-
using Ansible playbook, password is required.
60-
61-
Additional Notes
62-
================
63-
64-
- How to GitLab?
65-
* https://cisco.jiveon.com/docs/DOC-42998
144+
145+
```
146+
RP/0/RP0/CPU0:ios# conf t
147+
RP/0/RP0/CPU0:ios(config)# ssh server v2
148+
RP/0/RP0/CPU0:ios(config)# ssh server netconf vrf default
149+
RP/0/RP0/CPU0:ios(config)# ssh server logging
150+
RP/0/RP0/CPU0:ios(config)# xml agent ssl
151+
RP/0/RP0/CPU0:ios(config)# xml agent tty
152+
RP/0/RP0/CPU0:ios(config)# netconf agent tty
153+
RP/0/RP0/CPU0:ios(config)# netconf-yang agent ssh
154+
RP/0/RP0/CPU0:ios(config)# commit
155+
```
156+
- Optional SSH key setup allows user to connect to IOS-XR without password.
157+
First, generate base64 SSH key file on Ansible Server and copy it to your
158+
tftpboot directory.
159+
160+
```
161+
cut -d" " -f2 ~/.ssh/id_rsa.pub | base64 -d > ~/.ssh/id_rsa_pub.b64
162+
cp ~/.ssh/id_rsa_pub.b64 /tftpboot
163+
```
164+
- After IOS-XR is ready, at IOS-XR console prompt, import SSH key as followed
165+
166+
```
167+
RP/0/RP0/CPU0:ios# crypto key import authentication rsa tftp://192.168.1.1/id_rsa_pub.b64
168+
RP/0/RP0/CPU0:ios# show crypto key authentication rsa
169+
```
170+
- Now make sure you can connect to both XRV9K VMs management port from Linux host
171+
172+
```
173+
174+
ssh [email protected] "show run"
175+
```
176+
177+
- Setup the third party namespace (TPNNS) access on IOS-XR. Please refer to the
178+
following link for instruction and make sure you can SSH to the IOS-XR
179+
through port **57722**.
180+
181+
http://www.cisco.com/c/en/us/td/docs/iosxr/ncs5500/app-hosting/b-application-hosting-configuration-guide-ncs5500/b-application-hosting-configuration-guide-ncs5500_chapter_00.html
182+
183+
NOTE: Newer version of IOS-XR has renamed tpnns to operns resulting in filename changed, e.g. sshd_tpnns to sshd_operns
184+
185+
```
186+
RP/0/RP0/CPU0:aermongk-ss1# run
187+
[xr-vm_node0_RP0_CPU0:~]$ . /etc/init.d/operns-functions
188+
[xr-vm_node0_RP0_CPU0:~]$ operns_wait_until_ready
189+
[xr-vm_node0_RP0_CPU0:~]$ service sshd_operns start
190+
```
191+
192+
To access IOS-XR without password, you will also need to add your
193+
Linux server SSH public key (~/.ssh/id_rsa.pub) to your IOS-XR
194+
\<your_xr_home\>/.ssh/authorized_key file by using **ssh-copy-id**
195+
command, for example,
196+
197+
```
198+
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 57722 [email protected]
199+
```
200+
201+
- If your Linux server support HTTPS and you want a secure communication during
202+
SMU package installation, you can import your certificate from Linux to
203+
IOS-XR. The IOS-XR certificate store is in /etc/ssl/certs/ca-certificates.crt.
204+
Basically, you just need to cut and paste your certificate text to this file.
205+
206+
# Local mode setup and test
207+
208+
- Edit and source Ansible, YDK, and Python environment to point to your
209+
installed applications
210+
211+
```
212+
cd iosxr-ansible/local
213+
vi ansible_env
214+
source ansible_env
215+
```
216+
- Edit "ansible_hosts" file to change "ss-xr" host IP to your 2 XRV9K VMs
217+
218+
```
219+
[ss-xr]
220+
192.168.1.120 ansible_ssh_user=cisco
221+
192.168.1.121 ansible_ssh_user=cisco
222+
```
223+
- Run sample playbooks
224+
* Some of sample playbooks will require changes to fit your need
225+
e.g. edit iosxr_install_package.yml to change location of your package.
226+
227+
```
228+
cd samples
229+
ansible-playbook iosxr_get_config.yml
230+
ansible-playbook iosxr_clear_log.yml
231+
ansible-playbook iosxr_cli.yml -e 'cmd="show interface brief"'
232+
ansible-playbook iosxr_netconf_send.yml -e "xml_file=xml/nc11_show_install_active.xml"
233+
```
234+
# Remote mode setup and test
235+
236+
- Configure Ansible configuration to use port 57722 by editing your ansible
237+
config file (default is /etc/ansible/ansible.cfg) with following values
238+
239+
```
240+
[defaults]
241+
remote_port = 57722
242+
```
243+
- Edit Ansible and Python environment as needed in ansible_env and source it
244+
245+
```
246+
cd iosxr-ansible/remote
247+
vi ansible_env
248+
source ansible_env
249+
```
250+
- Edit "ansible_hosts" file to change "ss-xr" host IP to your 2 XRV9K VMs
251+
252+
```
253+
[ss-xr]
254+
192.168.1.120 ansible_ssh_user=cisco
255+
192.168.1.121 ansible_ssh_user=cisco
256+
```
257+
- Run sample playbooks
258+
* Some of sample playbooks will require changes to fit your need
259+
e.g. edit iosxr_install_package.yml to change location of your package.
260+
261+
```
262+
cd samples
263+
ansible-playbook iosxr_get_config.yml
264+
ansible-playbook iosxr_cli.yml -e 'cmd="show interface brief"'
265+
```
266+
# Local Mode Modules Description
267+
268+
* iosxr_clear_config - Clear all configurations on IOS-XR device
269+
* iosxr_clear_log - Clear system log
270+
* iosxr_cli - Run a command on IOS-XR device
271+
* iosxr_diff_config - Compare a given configuration file with the running configuration
272+
* iosxr_get_config - Show running configuration on IOS-XR device
273+
* iosxr_get_facts - Get status and information from IOS-XR device
274+
* iosxr_install_config - Commit a configuration file on IOS-XR device
275+
* iosxr_install_key - Install BASE64 crypto key on IOS-XR device
276+
* iosxr_install_package - Install SMU package on IOS-XR device
277+
* iosxr_nc10_send - Send NETCONF 1.0 XML file to IOS-XR device
278+
* iosxr_nc11_send - Send NETCONF-YANG 1.1 XML file to IOS-XR device
279+
* iosxr_reload - Reload IOS-XR device
280+
* iosxr_rollback - Rollback configuration on IOS-XR device
281+
* iosxr_upgrade_package - Upgrade packages on IOS-XR device
282+
* iosxr_xml_send - Performs Cisco XML request to IOS-XR device
283+
* xr32_install_package - Run install commands on IOS-XR device
284+
285+
**Sample Modules using Cisco YDK services**
286+
287+
* iosxr_show_install_active - show active package
288+
* iosxr_show_install_committed - show committed package
289+
* iosxr_show_install_inactive - show inactive package in the repository
290+
* iosxr_show_install_last_log - show installation log
291+
* iosxr_show_install_log - show installation log
292+
* iosxr_show_install_request - show current install request
293+
* iosxr_show_install_version - show current software install version
294+
295+
# Remote Mode Modules Description
296+
297+
* iosxr_clear_log - Clear system log
298+
* iosxr_cli - Run a command on IOS-XR device
299+
* iosxr_get_config - Show running configuration on IOS-XR device
300+
* iosxr_get_facts - Get status and information from IOS-XR device
301+
* iosxr_install_config - Commit configuration file on IOS-XR device
302+
* iosxr_install_package - Install SMU package on IOS-XR device
303+
* iosxr_reload - Reload IOS-XR device
304+
* iosxr_rollback - Rollback configuration on IOS-XR device
305+
306+
# IOS-XR platforms tested
307+
308+
- XRv9K (sunstone)
309+
- ASR9K (classic 32-bit QNX IOS-XR)
310+
- NCS1K (rosco)
311+
- NCS5500 (fretta)
312+
313+
# Ansible Test Setup
314+
315+
* 1 or more IOS-XR device(s)
316+
* 1 Linux server (ubuntu 15.10)
317+
* Create network connection between IOS-XR device and Linux server
66318

0 commit comments

Comments
 (0)