OcNOS DC : Ansible Guide : Getting Started
Getting Started
Overview
This guide demonstrates how Ansible can be used to manage OcNOS devices using a common generic framework of platform agnostic Ansible networking modules.
This guide shows:
Managing OcNOS devices through Ansible playbooks
Sample configuration jinja2 templates for protocols
Limitations
Install from Ansible Galaxy
The OcNOS Ansible module is installed from Ansible Galaxy.
1. Ensure the installed Ansible version is 2.9 or later.
Here is the example with Ansible version 2.9.6:
# ansible --version
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path =
[u'/home/ <yourhome> /.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.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623
(Red Hat 4.8.5-39)]
Here is the example with Ansible version 2.15.2:
# ansible --version
ansible [core 2.15.2]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /root/ansible-8.1.0/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /root/ansible-8.1.0/bin/ansible
python version = 3.9.17 (main, Jun 9 2023, 02:31:12) [GCC 10.3.1 20211027] (/root/ansible-8.1.0/bin/python)
jinja version = 3.1.2
libyaml = False
2. You might also need to install an SSH plugin such as Paramiko or Ansible-Pylibssh.
$ pip install paramiko
If your ansible.netcommon module version is 1.1.0 or later, libssh for ssh channel can be used.
$ pip install ansible-pylibssh
 
3. Install from Galaxy:
$ ansible-galaxy collection install ipinfusion.ocnos
 
4. When the standalone package is delivered, use the following command to install it on your system:
$ ansible-galaxy collection install ipinfusion-ocnos-x.x.x.tar.gz
Set up Ansible Files
$ cat group_vars/ocnos.yml
ansible_connection: network_cli
ansible_network_os: ipinfusion.ocnos.ocnos
ansible_become: yes
ansible_become_method: enable
ansible_ssh_user: ocnos
ansible_ssh_pass: ocnos
 
Note: The following inventory file is an example. Change the address and name for your site.
$ cat inventory/inventory.ini
[ocnosvm]
OcNOS-VM1 ansible_host=192.168.122.180 interface1=eth2
[ocnossw]
OcNOS-SW1 ansible_host=10.5.178.3 interface1=xe1/2
[ocnos:children]
ocnosvm
ocnossw
Modules
The ipinfusion.ocnos.ocnos_xxx is a prefix of OcNOS Ansible methods.xxx. Currently, the following methods are supported:
ipinfusion.ocnos.ocnos_fact
ipinfusion.ocnos.ocnos_command
ipinfusion.ocnos.ocnos_config
ipinfusion.ocnos.ocnos_ping
ipinfusion.ocnos.ocnos_bgp_facts
ipinfusion.ocnos.ocnos_isis_facts
For platform-agnostic modules like gather_facts, cli_command,cli_config, and net_ping, you do not need to change the module name since the platform is specified by ansible_network_os.
ipinfusion.ocnos.ocnos_facts
ocnos_facts collects facts from devices running OcNOS. Its result will be returned via the ansible_net_xxx variable.
Sample Playbook
---
- hosts: ocnos
 
tasks:
- name: Test OcNOS Facts
ipinfusion.ocnos.ocnos_facts:
gather_subset: all
register: result
 
- name: Show Facts
debug:
msg: The version is {{ ansible_net_version }}. HW model is {{ ansible_net_model }}, its serial is {{ ansible_net_serialnum }}
Sample Output
$ ansible-playbook -i inventory/inventory.ini fact-playbook.yml -l OcNOS-SW1
 
PLAY [ocnos] **************************************************************
 
TASK [Gathering Facts] ***************************************************
ok: [OcNOS-SW1]
 
TASK [Test OcNOS Facts] ***************************************************
ok: [OcNOS-SW1]
 
TASK [Show Facts] ********************************************************
ok: [OcNOS-SW1] => {
"msg": "The version is DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0. HW model is DELL S6000-ON, its serial is CN07VJDK282985730184"
}
 
PLAY RECAP ****************************************************************
OcNOS-SW1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
 
Return Values
 
Table 1-1: Return values 
Key
Returned
Description
ansible_net_all_ipv4_addresses
list
when interfaces are configured
All IPv4 addresses configured on the device
ansible_net_all_ipv6_addresses
list
when interfaces are configured
All IPv6 addresses configured on the device
ansible_net_config
string
when config is configured
The current active config from the device
ansible_net_gather_subset
list
always
The list of fact subsets collected from the device
ansible_net_hostname
string
always
The configured hostname of the device
ansible_net_image
string
always
The image file the device is running
ansible_net_interfaces
dict
when interfaces are configured
A hash of all interfaces running on the system
ansible_net_memfree_mb
int
when hardware is configured
The available free memory on the remote device in Mb
ansible_net_memtotal_mb
int
when hardware is configured
The total memory on the remote device in Mb
ansible_net_model
string
always
The model name returned from the device
ansible_net_neighbors
dict
when interfaces is configured
The list of LLDP neighbors from the remote device
ansible_net_serialnum
string
always
The serial number of the remote device
ansible_net_version
string
always
The operating system version running on the remote device
The parameters are not supported:
ansible_net_filesystem
ansible_net_api
The example below shows the parameters in the table and the playbook to get them.
playbook: fact-all-playbook.yml
---
- hosts: ocnos
 
tasks:
- name: Test OcNOS Facts
ipinfusion.ocnos.ocnos_facts:
gather_subset: all
register: result
 
- debug: var=ansible_net_all_ipv4_addresses
- debug: var=ansible_net_all_ipv6_addresses
- debug: var=ansible_net_gather_subset
- debug: var=ansible_net_hostname
- debug: var=ansible_net_image
- debug: var=ansible_net_interfaces
- debug: var=ansible_net_memfree_mb
- debug: var=ansible_net_memtotal_mb
- debug: var=ansible_net_model
- debug: var=ansible_net_neighbors
- debug: var=ansible_net_serialnum
- debug: var=ansible_net_version
 
Operation
$ ansible-playbook -i inventory/inventory.ini fact-all-playbook.yml -l OcNOS-SW1
 
PLAY [ocnos] **************************************************************************
 
TASK [Gathering Facts] ****************************************************************
ok: [OcNOS-SW1]
 
TASK [Test OcNOS Facts]****************************************************************
ok: [OcNOS-SW1]
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_all_ipv4_addresses": [
"127.0.0.1",
"127.0.0.1",
"10.5.178.3"
]
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_all_ipv6_addresses": [
"fe80::eef4:bbff:fe3e:c0ec",
"fe80::eef4:bbff:fe3e:c0ec",
"::1",
"::1",
"fe80::eef4:bbff:fefe:2beb"
]
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_gather_subset": [
"hardware",
"default",
"interfaces",
"config"
]
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_hostname": "OcNOS-SW1-1"
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_image": "DELL_S6000_ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0-installer"
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_interfaces": {
"eth0": {
"bandwidth": "1g(auto)",
"description": null,
"duplex": "full",
"ipv4": {
"address": "10.5.178.3",
"masklen": "22"
},
"ipv6": {
"address": "fe80::eef4:bbff:fefe:2beb",
"masklen": "64"
},
"lineprotocol": "up",
"macaddress": "ecf4.bbfe.2beb",
"mediatype": "METH",
"mtu": "1500"
},
"lo": {
"bandwidth": null,
"description": null,
"duplex": null,
"ipv4": {
"address": "127.0.0.1",
"masklen": "8"
},
"ipv6": {
"address": "::1",
"masklen": "128"
},
"lineprotocol": "up",
"macaddress": null,
"mediatype": "LB",
"mtu": null
},
"lo.management": {
"bandwidth": null,
"description": null,
"duplex": null,
"ipv4": {
"address": "127.0.0.1",
"masklen": "8"
},
"ipv6": {
"address": "::1",
"masklen": "128"
},
"lineprotocol": "up",
"macaddress": null,
"mediatype": "LB",
"mtu": null
},
"vlan1.1": {
"bandwidth": null,
"description": null,
"duplex": null,
"ipv4": null,
"ipv6": null,
"lineprotocol": "down",
"macaddress": "ecf4.bb3e.c0ec",
"mediatype": "SVI",
"mtu": null
},
"vlan1.10": {
"bandwidth": null,
"description": null,
"duplex": null,
"ipv4": null,
"ipv6": null,
"lineprotocol": "down",
"macaddress": "ecf4.bb3e.c0ec",
"mediatype": "SVI",
"mtu": null
},
"xe1/2": {
"bandwidth": null,
"description": "test interface set by ansible 9th",
"duplex": null,
"ipv4": null,
"ipv6": null,
"lineprotocol": "down",
"macaddress": "ecf4.bb3e.c0ec",
"mediatype": "ETH",
"mtu": null
},
----- Snipped ----
 
"xe9/2": {
"bandwidth": null,
"description": null,
"duplex": null,
"ipv4": null,
"ipv6": null,
"lineprotocol": "down",
"macaddress": "ecf4.bb3e.c0ec",
"mediatype": "ETH",
"mtu": null
}
}
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_memfree_mb": 7554
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_memtotal_mb": 7988
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_model": "DELL S6000-ON"
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_neighbors": {}
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_serialnum": "CN07VJDK282985730184"
}
 
TASK [debug]***************************************************************************
ok: [OcNOS-SW1] => {
"ansible_net_version": "1.3.8.44a"
}
 
PLAY RECAP ***************************************************************************
OcNOS-SW1 : ok=14 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
 
cli_command
cli_command is platform agnostic and it can also use OcNOS.
Parameters
Standard cli_command parameters are supported:
 
Table 1-2: Supported parameters 
Parameter
Choices/Defaults
Comments
answer
list
 
The answer to reply with if prompt is matched. The value can be a single answer or a list of answer for multiple prompts. In case the command execution results in multiple prompts the sequence of the prompt and excepted answer should be in same order.
check_all
boolean
Choices:
no (default)
yes
By default if any one of the prompts mentioned in prompt option is matched it won't check for other prompts. This boolean flag, that when set to True will check for all the prompts mentioned in prompt option in the given order. If the option is set to True all the prompts should be received from remote host if not it will result in timeout.
command
- / required
 
The command to send to the remote network device. The resulting output from the command is returned, unless send only is set.
newline
boolean
Choices:
no
yes (default)
The boolean value, that when set to false will send answer to the device without a trailing newline.
prompt
list
 
A single regex pattern or a sequence of patterns to evaluate the expected prompt from command.
sendonly
boolean
Choices:
no (default)
yes
The boolean value, that when set to true will send command to the device but not wait for a result.
Return Values
As well as the standard cli_command, common return values are supported. JSON is not supported.
 
Table 1-3: Return values 
Key
Returned
Description
stdout
string
when sendonly is false
The response from the command.
 
Sample:
Software version: DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0 [...]
Samples
The following is an example of show version.
 
Playbook:
---
- hosts: ocnos
 
tasks:
- name: Test OcNOS command
cli_command:
command: show version
register: result
 
- name: debug
debug:
msg: "{{ result.stdout_lines }}"
 
Output:
$ ansible-playbook -i inventory/inventory.ini clicommand-playbook.yml -l OcNOS-SW1
 
PLAY [ocnos] **************************************************************
 
TASK [Gathering Facts] ****************************************************
ok: [OcNOS-SW1]
 
TASK [Test OcNOS command] *************************************************
ok: [OcNOS-SW1]
 
TASK [debug] **************************************************************
ok: [OcNOS-SW1] => {
"msg": [
"Software version: DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0 09/28/2019 21:41:50",
" Copyright (C) 2019 IP Infusion. All rights reserved",
"",
" Software Product: OcNOS, Version: 1.3.8.44a",
" Hardware Model: DELL S6000-ON",
" Software Feature Code: DC-IPBASE",
" System Configuration Code: S0",
" Package Configuration Code: P0",
" Software Baseline Version: 1.3.8.44a",
"",
"Installation Information:",
" Image Filename: DELL_S6000_ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0-installer",
" Install method: tftp",
" ONIE SysInfo: x86_64-dell_s6000_s1220-r0"
]
}
 
PLAY RECAP ****************************************************************
OcNOS-SW1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
 
This example shows reload used with multiple prompts:
---
- hosts: ocnos
 
tasks:
- name: multiple prompt, multiple answer (mandatory check for all prompts)
cli_command:
command: reload
check_all: True
prompt:
- "Would you like to save them now?"
- "Are you sure you would like to reset the system?"
answer:
- 'y'
- 'y'
ipinfusion.ocnos.ocnos_command
cli_command can execute only one command per task since it doesn't support multiple commands parameters. Unlike cli_command, ocnos_command supports multiple commands.
Parameters
 
Table 1-4: Parameters 
Parameter
Choices/Defaults
Comments
commands
- / required
 
List of commands to send to the remote device over the configured provider. The resulting output from the command is returned. If the wait_for argument is provided, the module is not returned until the condition is satisfied or the number of retries as expired.
interval
-
Default:
1
Configures the interval in seconds to wait between retries of the command. If the command does not pass the specified conditions, the interval indicates how long to wait before trying the command again.
match
-
Choices:
any
all (default)
The match argument is used in conjunction with the wait_for argument to specify the match policy. Valid values are all or any. If the value is set to all then all conditionals in the wait_for must be satisfied. If the value is set to any then only one of the values must be satisfied.
provider
dictionary
 
A dict object containing connection details.
auth_pass
string
Specifies the password to use if required to enter privileged mode on the remote device. If authorize is false, then this argument does nothing. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTH_PASS will be used instead.
authorize
boolean
Choices:
no (default)
yes
Instructs the module to enter privileged mode on the remote device before sending any commands. If not specified, the device will attempt to execute all commands in non-privileged mode. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_AUTHORIZE will be used instead.
host
string / required
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
password
string
 
Specifies the password to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
port
integer
Default:
22
Specifies the port to use when building the connection to the remote device.
ssh_keyfile
path
 
Specifies the SSH key to use to authenticate the connection to the remote device. This value is the path to the key used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
timeout
integer
Default:
10
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error.
username
string
 
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
retries
-
Default:
10
Specifies the number of retries a command should be tried before it is considered failed. The command is run on the target device every retry and evaluated against the wait_for conditions.
wait_for
-
 
List of conditions to evaluate against the output of the command. The task will wait for each condition to be true before moving forward. If the conditional is not true within the configured number of retries, the task fails.
Return Values
 
Table 1-5: Return values
Key
Returned
Description
stdout
list
always
the set of responses from the commands.
stdout_lines
list
always
The value of stdout split into a list
Samples
The example below shows that three show commands can be specified in a task.
Playbook
---
- hosts: ocnos
 
tasks:
- name: Test OcNOS command
ipinfusion.ocnos. ocnos_command:
commands:
- show version
- show hardware-information memory
- show interface br
register: result
 
- name: Show Result
debug:
msg: "{{ result.stdout_lines }}"
 
cli_config
Parameters
Only the parameters below in standard Ansible cli_config are supported.
 
Table 1-6: Parameters
Parameter
Choices/Defaults
Comments
backup
boolean
Choices:
no (default)
yes
This argument will cause the module to create a full backup of the current running config from the remote device before any changes are made. If the backup_options value is not given, the backup file is written to the backup folder in the playbook root directory or role root directory, if playbook is part of an ansible role. If the directory does not exist, it is created.
backup_options
dictionary
 
This is a dict object containing configurable options related to backup file path. The value of this option is read only when backup is set to yes, if backup is set to no this option will be silently ignored.
dir_path
path
 
This option provides the path ending with directory name in which the backup configuration file will be stored. If the directory does not exist it will be first created and the filename is either the value of filename or default filename as described in filename options description. If the path value is not given in that case a backup directory will be created in the current working directory and backup configuration will be copied in filename within backup directory.
filename
-
 
The filename to be used to store the backup configuration. If the the filename is not given it will be generated based on the hostname, current time and date in format defined by <hostname>_config.<current-date>@<current-time>
config
string
 
The config to be pushed to the network device. This argument is mutually exclusive with rollback and either one of the option should be given as input. The config should have indentation that the device uses.
Return Values
 
Table 1-7: Return values
Key
Returned
Description
backup_path
string
when backup is yes
The full path to the backup file
 
Sample:
/playbooks/ansible/backup/hostname_config.2016-07-16@22:28:34
commands
list
always
The set of commands that will be pushed to the remote device
 
Sample:
['hostname foobar_by_cliconfig']
Samples
Playbook:
 
---
- hosts: ocnos
 
tasks:
- name: multiline config
cli_config:
config: |
hostname foo
bridge 1 protocol mstp
vlan 2-10 bridge 1
 
Output:
 
$ ansible-playbook -i inventory/inventory.ini cliconfig-playbook.yaml -l OcNOS-SW1
PLAY [ocnos] **************************************************************
 
TASK [Gathering Facts]****************************************************************
ok: [OcNOS-SW1]
 
TASK [multiline config]***************************************************************
changed: [OcNOS-SW1]
 
PLAY RECAP ****************************************************************
OcNOS-SW1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
 
 
Validation:
 
Note: The bold lines in show run indicate the configuration that was changed by this playbook.
$ ssh -l ocnos 10.5.178.3
ocnos@10.5.178.3's password:
Last login: Fri Dec 13 16:59:17 2019 from 10.5.176.106
 
OcNOS version DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0 09/28/2019 21:41:50
foo>en
foo#show spanning-tree mst detail
% 1: Bridge up - Spanning Tree Enabled
% 1: CIST Root Path Cost 0 - CIST Root Port 0 - CIST Bridge Priority 32768
% 1: Forward Delay 15 - Hello Time 2 - Max Age 20 - Transmit Hold Count 6 - Max-hops 20
% 1: CIST Root Id 8000000000000000
% 1: CIST Reg Root Id 8000000000000000
% 1: CIST Bridge Id 8000000000000000
% 1: 0 topology change(s) - last topology change Thu Jan 1 00:00:00 1970
 
% 1: portfast bpdu-filter disabled
% 1: portfast bpdu-guard disabled
foo#show run
!
! Software version: DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0 09/28/2019 21:41:50
!
!Last configuration change at 16:59:18 UTC Fri Dec 13 2019 by ocnos
!
no service password-encryption
!
logging monitor 7
!
ip vrf management
!
forwarding profile l2-profile-three
!
hostname foo
ip domain-lookup vrf management
no ip domain-lookup
bridge 1 protocol mstp
data-center-bridging enable bridge 1
feature telnet vrf management
feature ssh vrf management
snmp-server enable snmp vrf management
snmp-server view all .1 included vrf management
snmp-server community public group network-operator vrf management
feature ntp vrf management
ntp enable vrf management
username ocnos role network-admin password encrypted $1$we7czZA/$kGreh592N7ohrMdsGQUj5.
feature rsyslog vrf management
!
vlan database
vlan 2-10 bridge 1 state enable
!
spanning-tree mst configuration
!
interface eth0
ip vrf forwarding management
ip address dhcp
!
ipinfusion.ocnos.ocnos_config
This is a module equivalent in functionality with the platform-agnostic cli_config module.
Parameters
 
Table 1-8: Supported parameters 
Parameter
Choices/Defaults
Comments
after
-
 
The ordered set of commands to append to the end of the command stack if a change needs to be made. Just like with before this allows the playbook designer to append a set of commands to be executed after the command set.
backup
-
Choices:
no (default)
yes
This argument will cause the module to create a full backup of the current running-config from the remote device before any changes are made. If the backup_options value is not given, the backup file is written to the backup folder in the playbook root directory or role root directory, if playbook is part of an ansible role. If the directory does not exist, it is created.
backup_options
dictionary
 
This is a dict object containing configurable options related to backup file path. The value of this option is read only when backup is set to yes, if backup is set to no this option will be silently ignored.
dir_path
path
This option provides the path ending with directory name in which the backup configuration file will be stored. If the directory does not exist it will be first created and the filename is either the value of filename or default filename as described in filename options description. If the path value is not given in that case a backup directory will be created in the current working directory and backup configuration will be copied in filename within backup directory.
filename
-
 
The filename to be used to store the backup configuration. If the the filename is not given it will be generated based on the hostname, current time and date in format defined by <hostname>_config.<current-date>@<current-time>
before
-
 
The ordered set of commands to push on to the command stack if a change needs to be made. This allows the playbook designer the opportunity to perform configuration commands prior to pushing any changes without affecting how the set of commands are matched against the system.
diff_ignore_lines
-
 
Use this argument to specify one or more lines that should be ignored during the diff. This is used for lines in the configuration that are automatically updated by the system. This argument takes a list of regular expressions or exact line matches.
lines
-
 
The ordered set of commands that should be configured in the section. The commands must be the exact same commands as found in the device running-config. Be sure to note the configuration command syntax as some commands are automatically modified by the device config parser.
 
aliases: commands
match
-
Choices:
line (default)
strict
exact
none
Instructs the module on the way to perform the matching of the set of commands against the current device config. If match is set to line, commands are matched line by line. If match is set to strict, command lines are matched with respect to position. If match is set to exact, command lines must be an equal match. Finally, if match is set to none, the module will not attempt to compare the source configuration with the running configuration on the remote device.
parents
-
 
The ordered set of parents that uniquely identify the section or hierarchy the commands should be checked against. If the parents argument is omitted, the commands are checked against the set of top level or global commands.
replace
-
Choices:
line (default)
block
config
Instructs the module on the way to perform the configuration on the device. If the replace argument is set to line then the modified lines are pushed to the device in configuration mode. If the replace argument is set to block then the entire command block is pushed to the device in configuration mode if any line is not correct.
running_config
string
 
The module, by default, will connect to the remote device and retrieve the current running-config to use as a base for comparing against the contents of source. There are times when it is not desirable to have the task get the current running-config for every task in a playbook. The running_config argument allows the implementer to pass in the configuration to use as the base config for this module.
 
aliases: config
save_when
-
Choices:
always
never (default)
modified
changed
When changes are made to the device running-configuration, the changes are not copied to non-volatile storage by default. Using this argument will change that before. If the argument is set to always, then the running-config will always be copied to the startup-config and the modified flag will always be set to True. If the argument is set to modified, then the running-config will only be copied to the startup-config if it has changed since the last save to startup-config. If the argument is set to never, the running-config will never be copied to the startup-config. If the argument is set to changed, then the running-config will only be copied to the startup-config if the task has made a change.
src
-
 
The src argument provides a path to the configuration file to load into the remote system. The path can either be a full system path to the configuration file if the value starts with / or relative to the root of the implemented role or playbook. This argument is mutually exclusive with the lines and parents arguments. It can be a Jinja2 template as well. The src file must have same indentation as a live switch config.
Return Values
 
Table 1-9: Return values 
Key
Returned
Description
backup_path
string
When backup is yes
The full path to the backup file
 
Sample:
/home/somewhere/ansible/backup/OcNOS-SW1_config.2020-03-17@05:33:06
commands
list
Always
The set of commands that will be pushed to the remote device.
 
Sample:
['hostname OcNOS-SW1-20']
date
string
When backup is yes
The date extracted from the backup file name
 
Sample:
2020-03-17
filename
string
When backup is yes and filename is not specified in backup options
The name of the backup file
 
Sample:
OcNOS-SW1_config.2020-03-17@05:33:06
shortname
string
When backup is yes and filename is not specified in backup options
The full path to the backup file excluding the timestamp
 
Sample:
/home/somewhere/ansible/backup/OcNOS-SW1_config
time
string
when backup is yes
The time extracted from the backup file name
 
Sample:
05:33:06
Samples
Playbook:
 
---
- hosts: ocnos
gather_facts: false
 
tasks:
- name: Test OcNOS configs
ipinfusion.ocnos.ocnos_config:
lines: "hostname {{ inventory_hostname }}-1 "
 
- name: configure interface settings
ipinfusion.ocnos.ocnos_config:
lines:
- description test interface set by ansible
- ip address 172.16.101.5/24
parents: interface {{ interface1 }}
 
- name: configurable backup path
ipinfusion.ocnos.ocnos_config:
backup: yes
backup_options:
filename: backup-{{ inventory_hostname }}.cfg
dir_path: /home/momose/ansible/backup
 
Output:
 
$ ansible-playbook -i inventory/inventory.ini config-playbook.yaml -l OcNOS-SW1
 
PLAY [ocnos] **************************************************************
 
TASK [Test OcNOS configs]**************************************************
ok: [OcNOS-SW1]
 
TASK [configure interface settings] ***************************************
changed: [OcNOS-SW1]
 
TASK [configurable backup path] *******************************************
ok: [OcNOS-SW1]
 
PLAY RECAP ****************************************************************
OcNOS-SW1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
 
Validation:
 
$ ssh -l ocnos 10.5.178.3
ocnos@10.5.178.3's password:
Last login: Fri Dec 6 15:04:18 2019 from 10.5.176.106
 
OcNOS version DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0 09/28/2019 21:41:50
OcNOS-SW1-1>show run
!
! Software version: DELL_S6000-ON-OcNOS-1.3.8.44a-DC_IPBASE-S0-P0 09/28/2019 21:41:50
!
!Last configuration change at 15:04:22 UTC Fri Dec 06 2019 by ocnos
!
no service password-encryption
!
logging monitor 7
!
ip vrf management
!
forwarding profile l2-profile-three
!
hostname OcNOS-SW1-1
ip domain-lookup vrf management
no ip domain-lookup
feature telnet vrf management
feature ssh vrf management
snmp-server enable snmp vrf management
snmp-server view all .1 included vrf management
snmp-server community public group network-operator vrf management
feature ntp vrf management
ntp enable vrf management
username ocnos role network-admin password encrypted $1$we7czZA/$kGreh592N7ohrMdsGQUj5.
feature rsyslog vrf management
!
interface eth0
ip vrf forwarding management
ip address dhcp
!
interface lo
ip address 127.0.0.1/8
ipv6 address ::1/128
!
interface lo.management
ip vrf forwarding management
ip address 127.0.0.1/8
ipv6 address ::1/128
!
interface xe1/1
!
interface xe1/2
description test interface set by ansible
ip address 172.16.100.5/24
!
interface xe1/3
!
interface xe1/4
!
interface xe2
!
interface xe3/1
port breakout enable
!
interface xe3/2
switchport
!
interface xe3/3
!
interface xe3/4
!
interface xe4
!
interface xe5/1
!
interface xe5/2
!
interface xe5/3
!
interface xe5/4
 
OcNOS-SW1-1>show int xe1/2
Interface xe1/2
Scope: both
Flexport: Non Control Port (InActive)
Hardware is ETH Current HW addr: ecf4.bb3e.c0ec
Physical:ecf4.bb3e.c0ee Logical:(not set)
Description: test interface set by ansible
Port Mode is Router
Interface index: 10002
Metric 1 mtu 1500
<UP,BROADCAST,MULTICAST>
VRF Binding: Not bound
DHCP client is disabled.
Last Flapped: Never
Statistics last cleared: Never
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
RX
unicast packets 0 multicast packets 0 broadcast packets 0
input packets 0 bytes 0
jumbo packets 0
undersize 0 oversize 0 CRC 0 fragments 0 jabbers 0
input error 0
input with dribble 0 input discard 0
Rx pause 0
TX
unicast packets 0 multicast packets 0 broadcast packets 0
output packets 0 bytes 0
jumbo packets 0
output errors 0 collision 0 deferred 0 late collision 0
output discard 0
Tx pause 0
OcNOS-SW1-1>exit
 
Verify the backup file was created:
 
$ ls -lsa backup/
total 8
0 drwxrwxrwx 2 momose momose 33 Dec 17 07:33 .
4 drwxrwxr-x 7 momose momose 4096 Dec 17 07:32 ..
4 -rw-rw-r-- 1 momose momose 3144 Dec 17 07:33 backup-OcNOS-SW1.cfg
 
ipinfusion.ocnos.ocnos_ping / net_ping
These modules are similar. net_ping uses ocnos_ping when ansible_network_os is set to ipinfusion.ocnos.ocnos.
Parameters
 
Table 1-10: Supported Parameters
Parameter
Choices/Defaults
Comments
count
-
Default: 5
Number of packets to send.
dest
/ required
 
The IP Address or hostname (resolvable by switch) of the remote node.
state
-
Choices:
absent
present (default)
Determines if the expected result is success or fail.
vrf
-
Default: "management"
The VRF to use for forwarding.
Return Values
 
Table 1-11: Return Values
Key
Returned
Description
commands
list
always
Show the command sent.
Sample:
['ping\nip\n \n192.168.122.1\n3\n64\n1\n100\n2\n0\nn\nn\n']
packet_loss
string
always
Percentage of packets lost.
Sample:
0%
packets_rx
integer
always
Packets successfully received.
Sample:
3
packets_tx
integer
always
Packets successfully transmitted.
Sample:
3
rtt
dictionary
always
Show RTT stats.
Sample:
{"avg": 0.115, "max": 0.135, "min": 0.079}
Sample
 
Playbook:
---
- hosts: ocnos
tasks:
- name: Test OcNOS Ping
ipinfusion.ocnos.ocnos_ping:
dest: 192.168.122.1
interface: eth0
count: 3
vrf: " "
register: result
 
Output:
$ ansible-playbook -i inventory/inventory.ini ocnos_ping.yml -l OcNOS-VM1
PLAY [ocnos]******************************************************************************
TASK [Test OcNOS Ping]*****************************************************************
ok: [OcNOS-VM1]
TASK [Show Result]*********************************************************************
ok: [OcNOS-VM1] => {
"msg": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"commands": "ping\nip\n \n192.168.122.1\n3\n64\n1\n100\n2\n0\nn\nn\n",
"failed": false,
"packet_loss": "0%",
"packets_rx": 3,
"packets_tx": 3,
"rtt": {
"avg": 0.119,
"max": 0.122,
"min": 0.115
}
}
}
PLAY RECAP ***************************************************************************
OcNOS-VM1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ipinfusion.ocnos.ocnos_bgp_facts
This module provides BGP related information. Currently, this supports only bgp neighbors.
Sample Playbook
fact-bgp.yml
---
hosts: ocnos
gather_facts: no
tasks:
- name: Test OcNOS Facts
ipinfusion.ocnos.ocnos_bgp_facts:
gather_subset: neighbor
register: result
- name: Show Facts
debug:
msg: "{{ ansible_facts }}"
Sample Output
$ ansible-playbook -i inventory/inventory.ini fact-bgp.yml -l OcNOS-VM1
 
PLAY [ocnos]***************************************************************************
 
TASK [Test OcNOS Facts]****************************************************************
ok: [OcNOS-VM1] => {
"msg": {
"discovered_interpreter_python": "/usr/bin/python",
"ansible_net_bgp_neighbor": {
"10.10.10.10": {
"Received": {
"InQueue": 0,
"messages": 0,
"notifications": 0
},
"Sent": {
"InQueue": 0,
"messages": 799,
"notifications": 0
},
"addressFamily": {
"IPv4 Unicast": {
"BGPtableVer": 1,
"acceptedPrefixes": 0,
"announcedPrefixes": 0,
"index": 1,
"mask": "0x2",
"neighborVer": 0,
"offset": 0
},
"VPNv4 Unicast": {
"BGPtableVer": 1,
"acceptedPrefixes": 0,
"announcedPrefixes": 0,
"index": 1,
"mask": "0x2",
"neighborVer": 0,
"offset": 0
}
},
"connections": {
"dropped": 0,
"established": 0
},
"holdTime": 90,
"keepAlive": 30,
"lastRead": "Never",
"localAS": "100",
"minTimeBetweenAdv": 5,
"remoteAS": "100",
"routeRefreshRequest": {
"received": 0,
"sent": 0
},
"state": "Active"
},
"2001:500:602::101": {
"Received": {
"InQueue": 0,
"messages": 0,
"notifications": 0
},
"Sent": {
"InQueue": 0,
"messages": 0,
"notifications": 0
},
"addressFamily": {
"IPv4 Unicast": {
"BGPtableVer": 1,
"acceptedPrefixes": 0,
"announcedPrefixes": 0,
"index": 2,
"mask": "0x4",
"neighborVer": 0,
"offset": 0
}
},
"connections": {
"dropped": 0,
"established": 0
},
"holdTime": 90,
"keepAlive": 30,
"lastRead": "Never",
"localAS": "100",
"minTimeBetweenAdv": 5,
"remoteAS": "100",
"routeRefreshRequest": {
"received": 0,
"sent": 0
},
"state": "Connect"
}
},
"ansible_net_gather_subset": [
"neighbor"
]
}
}
 
PLAY RECAP ***************************************************************************
OcNOS-VM1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ipinfusion.ocnos.ocnos_isis_facts
This module provides IS-IS related information. Currently, this supports only IS-IS neighbors.
net_isis_neighbor reads the output of ‘show clns neighbors’ , analyzes and converts it to ansible output format.
Sample Playbook
fact-isis.yml
---
- hosts: ocnos
gather_facts: no
tasks:
- name: Test OcNOS ISIS facts
ipinfusion.ocnos.ocnos_isis_facts:
gather_subset: neighbor
register: result
 
 
- name: Show ISIS Facts
debug:
msg: "{{ result }}"
Sample Output
$ ansible-playbook -i inventroy/inventory.ini fact-isis.yml -l OcNOS-VM1
 
PLAY [ocnos]***************************************************************************
 
TASK [Test OcNOS Facts]****************************************************************
ok: [OcNOS-VM1]
 
TASK [Show Facts]**********************************************************************
ok: [OcNOS-VM1] => {
"msg": {
"discovered_interpreter_python": "/usr/bin/python",
"net_gather_subset": [
"neighbor"
],
"net_isis_neighbor": {
"0000.0000.0001": {
"Holdtime": "21",
"Interface": "eth1",
"Protocol": "IS-IS",
"SNPA": "5254.0027.4096",
"State": "Up",
"Type": "L2"
}
}
}
}
 
PLAY RECAP ***************************************************************************
OcNOS-VM1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0