Reorganize integration tests:

- Move legacy tests into a separate directory.
- Reduce common dependencies between targets.
This commit is contained in:
Matt Clay 2017-09-13 17:31:44 -07:00
commit 781fd7099a
513 changed files with 111 additions and 6 deletions

View file

@ -0,0 +1,339 @@
- name: Create virtual network
azure_rm_virtualnetwork:
name: vnet001
resource_group: "{{ resource_group }}"
address_prefixes_cidr: "10.10.0.0/16"
register: output
- name: Create subnet
azure_rm_subnet:
name: subnet001
resource_group: "{{ resource_group }}"
virtual_network_name: vnet001
address_prefix_cidr: "10.10.0.0/24"
register: output
- name: Create second virtual network
azure_rm_virtualnetwork:
name: vnet002
resource_group: "{{ resource_group }}"
address_prefixes_cidr: "10.20.0.0/16"
register: output
- name: Create second subnet
azure_rm_subnet:
name: subnet002
resource_group: "{{ resource_group }}"
virtual_network_name: vnet002
address_prefix_cidr: "10.20.0.0/24"
register: output
- name: Create security group
azure_rm_securitygroup:
name: secgroup001
resource_group: "{{ resource_group }}"
register: output
- name: Create second security group
azure_rm_securitygroup:
name: secgroup002
resource_group: "{{ resource_group }}"
register: output
- name: Create a public ip
azure_rm_publicipaddress:
name: publicip001
resource_group: "{{ resource_group }}"
allocation_method: "Static"
register: output
- name: Create second public ip
azure_rm_publicipaddress:
name: publicip002
resource_group: "{{ resource_group }}"
allocation_method: "Static"
register: output
- name: Delete network interface, if it exists
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
state: absent
register: output
- name: Should require subnet when creating nic
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
virtual_network_name: vnet001
security_group_name: secgroup001
public_ip_address_name: publicip001
register: output
ignore_errors: yes
- assert:
that:
- output.failed
- "'subnet' in output.msg"
- name: Should require virtual network when creating nic
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
security_group_name: secgroup001
public_ip_address_name: publicip001
subnet: subnet001
register: output
ignore_errors: yes
- assert:
that:
- output.failed
- "'virtual_network_name' in output.msg"
- name: Create nic
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
virtual_network_name: vnet001
subnet: subnet001
security_group_name: secgroup001
public_ip_address_name: publicip001
register: output
- name: Should be idempotent
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
virtual_network_name: vnet001
subnet: subnet001
security_group_name: secgroup001
public_ip_address_name: publicip001
register: output
- assert:
that: not output.changed
- name: Should change private IP address
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
private_ip_address: 10.10.0.10
private_ip_allocation_method: Static
virtual_network_name: vnet001
subnet: subnet001
security_group_name: secgroup001
public_ip_address_name: publicip001
register: output
- assert:
that:
- output.changed
- output.state.ip_configuration.private_ip_address == '10.10.0.10'
- output.state.ip_configuration.private_ip_allocation_method == 'Static'
- name: Should change virtual network and subnet
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
private_ip_allocation_method: Dynamic
virtual_network_name: vnet002
subnet: subnet002
security_group_name: secgroup002
public_ip_address_name: publicip002
register: output
- assert:
that:
- output.changed
- "'10.20' in output.state.ip_configuration.private_ip_address"
- output.state.ip_configuration.private_ip_allocation_method == 'Dynamic'
- output.state.ip_configuration.subnet.name == 'subnet002'
- output.state.ip_configuration.public_ip_address.name == 'publicip002'
- name: Add tags
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
tags:
testing: testing
foo: bar
register: output
- assert:
that:
- output.state.tags | length == 2
- output.state.tags.testing == 'testing'
- name: Gather facts for tags
azure_rm_networkinterface_facts:
tags: testing
register: output
- assert:
that:
- azure_networkinterfaces | length >= 1
- name: Gather facts for resource group and tags
azure_rm_networkinterface_facts:
resource_group: "{{ resource_group }}"
tags: testing
register: output
- assert:
that:
- azure_networkinterfaces| length == 1
- name: Gather facts for name and tags
azure_rm_networkinterface_facts:
resource_group: "{{ resource_group }}"
name: nic003
tags: testing
register: output
- assert:
that:
- azure_networkinterfaces | length == 1
- name: Purge one tag
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
tags:
testing: testing
register: output
- assert:
that:
- output.changed
- output.state.tags | length == 1
- name: Purge all tags
azure_rm_networkinterface:
name: nic003
resource_group: "{{ resource_group }}"
tags: {}
register: output
- assert:
that:
- output.changed
- output.state.tags | length == 0
- name: Remove network interface, if it exists
azure_rm_networkinterface:
name: "{{ item }}"
resource_group: "{{ resource_group }}"
state: absent
register: output
with_items:
- nic004
- nic005
- name: Remove publicip, if it exists
azure_rm_publicipaddress:
name: "{{ item }}"
resource_group: "{{ resource_group }}"
state: absent
with_items:
- nic00401
- nic00501
- name: Remove security group, if it exists
azure_rm_securitygroup:
name: "{{ item }}"
resource_group: "{{ resource_group }}"
state: absent
with_items:
- nic00401
- nic00501
- name: Should create default security group and default public ip for linux host
azure_rm_networkinterface:
name: nic004
resource_group: "{{ resource_group }}"
virtual_network_name: vnet001
subnet: subnet001
register: output
- assert:
that:
- output.state.ip_configuration.public_ip_address.name == 'nic00401'
- output.state.network_security_group.name == 'nic00401'
- name: Gather facts for security group nic00401
azure_rm_securitygroup_facts:
resource_group: "{{ resource_group }}"
name: nic00401
register: output
- assert:
that:
- azure_securitygroups[0].properties.securityRules[0].properties.destinationPortRange == '22'
- name: Should create default security group and default public ip for windows host
azure_rm_networkinterface:
name: nic005
resource_group: "{{ resource_group }}"
virtual_network_name: vnet001
subnet: subnet001
os_type: Windows
open_ports:
- 9000
- '9005-9010'
register: output
- assert:
that:
- output.state.ip_configuration.public_ip_address.name == 'nic00501'
- output.state.network_security_group.name == 'nic00501'
- name: Gather facts for security group nic00501
azure_rm_securitygroup_facts:
resource_group: "{{ resource_group }}"
name: nic00501
register: output
- name: Security group should allow RDP access on custom port
assert:
that:
- azure_securitygroups[0].properties.securityRules[0].properties.destinationPortRange == '9000'
- azure_securitygroups[0].properties.securityRules[1].properties.destinationPortRange == '9005-9010'
- name: Gather facts for one nic
azure_rm_networkinterface_facts:
resource_group: "{{ resource_group }}"
name: nic003
register: output
- assert:
that:
- azure_networkinterfaces | length == 1
- name: Gather facts for all nics in resource groups
azure_rm_networkinterface_facts:
resource_group: "{{ resource_group }}"
register: output
- assert:
that:
- azure_networkinterfaces | length >= 3
- name: Gather facts for all nics
azure_rm_networkinterface_facts:
register: output
- assert:
that:
- azure_networkinterfaces | length >= 3
- name: Delete nic
azure_rm_networkinterface:
name: "{{ item }}"
resource_group: "{{ resource_group }}"
state: absent
register: output
with_items:
- nic003
- nic004
- nic005

View file

@ -0,0 +1,142 @@
- name: Get resource group
azure_rm_resourcegroup_facts:
name: "{{ resource_group }}"
- name: Create resource group
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
location: "{{ azure_resourcegroups[0].location }}"
tags:
testing: testing
delete: never
register: output
- assert:
that:
- output.state.tags.testing == 'testing'
- output.state.tags.delete == 'never'
- output.state.location == '{{ location }}'
- name: Should be idempotent
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
tags:
testing: testing
delete: never
register: output
- assert:
that: not output.changed
- name: Change resource group tags
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
tags:
testing: 'no'
delete: 'on-exit'
foo: 'bar'
register: output
- assert:
that:
- output.state.tags | length == 3
- output.state.tags.testing == 'no'
- output.state.tags.delete == 'on-exit'
- output.state.tags.foo == 'bar'
- name: Gather facts by tags
azure_rm_resourcegroup_facts:
tags:
- testing
- foo:bar
register: output
- assert:
that: azure_resourcegroups | length == 1
- name: Purge one tag
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
tags:
testing: 'no'
delete: 'on-exit'
debug: yes
register: output
- assert:
that:
- output.state.tags | length == 2
- output.state.tags.testing == 'no'
- output.state.tags.delete == 'on-exit'
- name: Purge no tags
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
register: output
- assert:
that:
- output.state.tags | length == 2
- name: Purge all tags
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
tags: {}
register: output
- assert:
that:
- output.state.tags | length == 0
- name: Add a resource
azure_rm_virtualnetwork:
resource_group: "{{ resource_prefix }}"
name: "virtualnet01"
address_prefixes_cidr: '10.1.0.0/16'
register: output
- name: Remove resource group should fail
azure_rm_resourcegroup:
name: "{{ resource_prefix }}"
state: absent
register: output
ignore_errors: yes
- assert:
that:
- output.failed
- "'Resources exist' in output.msg"
- name: Create a second resource group
azure_rm_resourcegroup:
name: Testing2
location: "{{ location }}"
register: output
- name: Gather facts for a resource group
azure_rm_resourcegroup_facts:
name: "{{ resource_group }}"
register: output
- assert:
that: azure_resourcegroups | length == 1
- name: Gather facts for all resource groups
azure_rm_resourcegroup_facts:
register: output
- assert:
that: azure_resourcegroups | length > 1
- name: Force remove resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
state: absent
force: yes
register: output
- name: Remove second resource group
azure_rm_resourcegroup:
name: Testing2
state: absent
register: output

View file

@ -0,0 +1,8 @@
ssh_keys:
- path: '/home/chouseknecht/.ssh/authorized_keys'
key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1igsIlcmTa/yfsJnTtnrEX7PP/a01gwbXcig6JOKyrUmJB8E6c/wtZwP115VSyDRTO6TEL/sBFUpkSw01zM8ydNATErh8meBlAlbnDq5NLhDXnMizgG0VNn0iLc/WplFTqkefsHXa8NtIxAtyEVIj/fKbK3XfBOdEpE3+MJYNtGlWyaod28W+5qmQPZDQys+YnE4OjSwN7D3g85/7dtLFvDH+lEC4ooJOaxVFr9VSMXUIkaRF6oI+R1Zu803LFSCTb4BfFOYOHPuQ/rEMP0KuUzggvP+TEBY14PEA2FoHOn+oRsT0ZR2+loGRaxSVqCQKaEHbNbkm+6Rllx2NQRO0BJxCSKRU1iifInLPxmSc4gvsHCKMAWy/tGkmKHPWIfN8hvwyDMK5MNBp/SJ1pVx4xuFDQjVWNbll0yk2+72uJgtFHHwEPK9QsOz45gX85vS3yhYCKrscS/W9h2l36SWwQXuGy4fXotE7esPsvNGAzBndHX1O8RMPg47qJXz059RyoGforoa9TnzIs3hIv+ts7ESx3OEq3HNk0FJ+wDka7IM7WQpGrVToJ0vfDy9Q46nw54vv5Zc/u4OZF3F5twHmyf3rLYKXRDuCvZQKT2iWQKVX6j63bq6orA5hwl22zndxWZNtOwtq8Sd0Ns0K/Fo/ggYDDGBtr68DwhA+MrxrHw== chouseknecht@ansible.com"
image:
offer: CentOS
publisher: OpenLogic
sku: '7.1'
version: latest

View file

@ -0,0 +1,2 @@
- include: virtualmachine.yml
#- include: virtualmachine_with_defaults.yml

View file

@ -0,0 +1,157 @@
- name: Delete virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
state: absent
vm_size: Standard_A0
register: output
- name: Create storage account name
set_fact:
storage_account: "{{ resource_group | hash('md5') | truncate(24, True, '') }}"
- name: Create storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Standard_LRS
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: testvm001
address_prefixes: "10.10.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: testvm001
address_prefix: "10.10.0.0/24"
virtual_network: testvm001
- name: Create public ip
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Static
name: testvm001
- name: Create security group
azure_rm_securitygroup:
resource_group: "{{ resource_group }}"
name: testvm001
- name: Create NIC
azure_rm_networkinterface:
resource_group: "{{ resource_group }}"
name: testvm001
virtual_network: testvm001
subnet: testvm001
public_ip_name: testvm001
security_group: testvm001
- name: Create virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
vm_size: Standard_A0
storage_account: "{{ storage_account }}"
storage_container: testvm001
storage_blob: testvm001.vhd
admin_username: adminuser
admin_password: Password123!
short_hostname: testvm
os_type: Linux
network_interfaces: testvm001
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: output
- name: Restart the virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
restarted: yes
vm_size: Standard_A0
register: output
- assert:
that:
- "azure_vm.powerstate in ['starting', 'running']"
- output.changed
- name: Deallocate the virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
allocated: no
vm_size: Standard_A0
register: output
- assert:
that:
- azure_vm.powerstate == 'deallocated'
- output.changed
- name: Start the virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
vm_size: Standard_A0
register: output
- assert:
that:
- "azure_vm.powerstate in ['starting', 'running']"
- output.changed
- name: Should be idempotent
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
vm_size: Standard_A0
storage_account: "{{ storage_account }}"
storage_container: testvm001
storage_blob: testvm001.vhd
admin_username: adminuser
admin_password: Password123!
short_hostname: testvm
os_type: Linux
network_interfaces: testvm001
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: output
- assert:
that: not output.changed
- name: Delete VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm002
state: absent
vm_size: Standard_A0
register: output
- name: NIC should be gone
azure_rm_networkinterface_facts:
resource_group: "{{ resource_group }}"
name: testvm001
register: output
- assert:
that: azure_networkinterfaces | length == 0
- name: PIP should be gone
azure_rm_publicipaddress_facts:
resource_group: "{{ resource_group }}"
name: testvm001
register: output
- assert:
that: azure_publicipaddresses | length == 0

View file

@ -0,0 +1,106 @@
- name: Remove VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm10
state: absent
vm_size: Standard_A0
register: output
- name: Remove VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm20
state: absent
vm_size: Standard_A0
register: output
- name: Create VM with defaults
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm10
vm_size: Standard_A0
admin_username: chouseknecht
admin_password: Password123
short_hostname: test10
os_type: Linux
open_ports:
- "22-23"
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: output
- name: Add host
add_host:
groups: just_created
hostname: testvm10
ansible_host: "{{ azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}"
ansible_user: chouseknecht
ansible_ssh_pass: Password123
- name: Create VM accessible via ssh keys only
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm20
short_hostname: testvm20
ssh_password_enabled: false
ssh_public_keys:
- path: /home/chouseknecht/.ssh/authorized_keys
key_data: "{{ lookup('env', 'HOME') }}/.ssh/id_rsa"
vm_size: Standard_A0
admin_username: chouseknecht
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: output
- name: Should be idempotent
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm20
short_hostname: testvm20
ssh_password_enabled: false
ssh_public_keys:
- path: /home/chouseknecht/.ssh/authorized_keys
key_data: "{{ lookup('env', 'HOME') }}/.ssh/id_rsa"
vm_size: Standard_A0
admin_username: chouseknecht
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: output
- assert:
that: not output.changed
- name: Add host
add_host:
groups: just_created
hostname: testvm20
ansible_ssh_host: "{{ azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}"
ansible_ssh_user: chouseknecht
- name: Power Off
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm10
started: no
register: output
- assert:
that: "azure_vm.powerstate not in ['starting', 'running']"
- name: Power On
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: testvm10
register: output
- assert:
that: "azure_vm.powerstate in ['starting', 'running']"

View file

@ -0,0 +1,5 @@
---
cloudscale_test_flavor: flex-2
cloudscale_test_image: debian-8
cloudscale_test_ssh_key: |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPmiqkvDH1/+MDAVDZT8381aYqp73Odz8cnD5hegNhqtXajqtiH0umVg7HybX3wt1HjcrwKJovZURcIbbcDvzdH2bnYbF93T4OLXA0bIfuIp6M86x1iutFtXdpN3TTicINrmSXEE2Ydm51iMu77B08ZERjVaToya2F7vC+egfoPvibf7OLxE336a5tPCywavvNihQjL8sjgpDT5AAScjb3YqK/6VLeQ18Ggt8/ufINsYkb+9/Ji/3OcGFeflnDXq80vPUyF3u4iIylob6RSZenC38cXmQB05tRNxS1B6BXCjMRdy0v4pa7oKM2GA4ADKpNrr0RI9ed+peRFwmsclH test@ansible

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,138 @@
---
- name: Test create server
cloudscale_server:
name: '{{ resource_prefix }}-test'
flavor: '{{ cloudscale_test_flavor }}'
image: '{{ cloudscale_test_image }}'
ssh_keys: '{{ cloudscale_test_ssh_key }}'
register: server
- name: Verify create server
assert:
that:
- server|success
- server|changed
- server.state == 'running'
- name: Test create server indempotence
cloudscale_server:
name: '{{ resource_prefix }}-test'
flavor: '{{ cloudscale_test_flavor }}'
image: '{{ cloudscale_test_image }}'
ssh_keys: '{{ cloudscale_test_ssh_key }}'
register: server
- name: Verify create server
assert:
that:
- server|success
- not server|changed
- server.state == 'running'
- name: Test create server stopped
cloudscale_server:
name: '{{ resource_prefix }}-test-stopped'
flavor: '{{ cloudscale_test_flavor }}'
image: '{{ cloudscale_test_image }}'
ssh_keys: '{{ cloudscale_test_ssh_key }}'
state: 'stopped'
register: server_stopped
- name: Verify create server stopped
assert:
that:
- server_stopped|success
- server_stopped|changed
- server_stopped.state == 'stopped'
- name: Test create server failure without required parameters
cloudscale_server:
name: '{{ resource_prefix }}-test-failed'
register: server_failed
ignore_errors: True
- name: Verify create server failure without required parameters
assert:
that:
- server_failed|failed
- "'Missing required parameter' in server_failed.msg"
- name: Test server stopped
cloudscale_server:
name: '{{ resource_prefix }}-test'
state: 'stopped'
register: server
- name: Verify server stopped
assert:
that:
- server|success
- server|changed
- server.state == 'stopped'
- name: Test server stopped indempotence
cloudscale_server:
name: '{{ resource_prefix }}-test'
state: 'stopped'
register: server
- name: Verify server stopped indempotence
assert:
that:
- server|success
- not server|changed
- server.state == 'stopped'
- name: Test server running
cloudscale_server:
name: '{{ resource_prefix }}-test'
state: 'running'
register: server
- name: Verify server running
assert:
that:
- server|success
- server|changed
- server.state == 'running'
- name: Test server running indempotence
cloudscale_server:
name: '{{ resource_prefix }}-test'
state: 'running'
register: server
- name: Verify server running indempotence
assert:
that:
- server|success
- not server|changed
- server.state == 'running'
- name: Test server deletion by name
cloudscale_server:
name: '{{ resource_prefix }}-test'
state: 'absent'
register: server
- name: Verify server deletion
assert:
that:
- server|success
- server|changed
- server.state == 'absent'
- name: Test server deletion by uuid
cloudscale_server:
uuid: '{{ server_stopped.uuid }}'
state: 'absent'
register: server_stopped
- name: Verify server deletion by uuid
assert:
that:
- server_stopped|success
- server_stopped|changed
- server_stopped.state == 'absent'
- name: Test server deletion indempotence
cloudscale_server:
name: '{{ resource_prefix }}-test'
state: 'absent'
register: server
- name: Verify server deletion
assert:
that:
- server|success
- not server|changed
- server.state == 'absent'

View file

@ -0,0 +1,113 @@
# Ansible Role: cnos_backup_sample - Saving the switch configuration to a remote server
---
<add role description below>
This role is an example of using the *cnos_backup.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with switch configurations. It provides a way to back up the running or startup configurations of a switch to a remote server. This is achieved by periodically saving a copy of the startup or running configuration of the network device to a remote server using FTP, SFTP, TFTP, or SCP.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_backup](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_backup.html&cp=0_3_1_0_4_4).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`configType` | Specifies the type of configuration to be backed up to the remote server (**running-config** - running configuration, **startup-config** - startup configuration)
`protocol` | Specifies the protocol used by the network device to interact with the remote server to where to upload the backup configuration (**ftp** - FTP, **sftp** - SFTP, **tftp** - TFTP, **scp** - SCP)
`serverip` | Specifies the IP Address of the remote server to where the configuration will be backed up
`rcpath` | Specifies the full file path where the configuration file will be copied on the remote server (when backing up the switch configuration through TFTP, an empty directory needs to be created, otherwise the operation will fail)
`serverusername` | Configures the username for the server relating to the protocol used
`serverpassword` | Configures the password for the server relating to the protocol used
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_backup.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_backup_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_backup_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_backup_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to back up configuration
hosts: cnos_backup_sample
gather_facts: no
connection: local
roles:
- cnos_backup_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,18 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_backup_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_backup_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos rcpath=/root/cnos_config/G8272-running-config.txt
#Use this in case its TFTP as tftpboot folder is the starting point for tftp
#10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos rcpath=/anil/G8272-running-config.txt

View file

@ -0,0 +1,24 @@
# This contain sample config back up tasks
---
- name: Test Running Config Backup
cnos_backup: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_backup_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}} serverusername='{{item.serverusername}}' serverpassword='{{item.serverpassword}}'
with_items: "{{test_config_data1}}"
- name: Test Startup Config Backup
cnos_backup: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_backup_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}} serverusername='{{item.serverusername}}' serverpassword='{{item.serverpassword}}'
with_items: "{{test_config_data2}}"
#Root folder will be different for SFTP/SCP and TFTP
#The following task is commented.
#Before trying this, please change in /etc/ansible/hosts file
#and backup the config file with reference to your tftp-root folder
#- name: Test Running Config Backup -TFTP
# cnos_backup: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_backup_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}}
# with_items: "{{test_config_data3}}"
#- name: Test Startup Config Backup - TFTP
# cnos_backup: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_backup_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}}
# with_items: "{{test_config_data4}}"
# Completed file

View file

@ -0,0 +1,12 @@
---
test_config_data1:
- {configType: running-config, protocol: "sftp", serverip: "10.241.106.118", serverusername: "root", serverpassword: "root123"}
test_config_data2:
- {configType: startup-config, protocol: "sftp", serverip: "10.241.106.118", serverusername: "root", serverpassword: "root123"}
test_config_data3:
- {configType: running-config, protocol: "tftp", serverip: "10.241.106.118"}
test_config_data4:
- {configType: startup-config, protocol: "tftp", serverip: "10.241.106.118"}

View file

@ -0,0 +1,118 @@
# Ansible Role: cnos_bgp_sample - CNOS Switch BGP Configuration
---
<add role description below>
This role is an example of using the *cnos_bgp.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with Border Gateway Protocol (BGP) related configurations. The operators used are overloaded to ensure control over switch BGP configurations. This module is invoked using method with *asNumber* as one of its arguments.
The first level of the BGP configuration allows to set up an AS number, with the following attributes going into various configuration operations under the context of BGP. After passing this level, there are eight BGP arguments that will perform further configurations. They are *bgpArg1*, *bgpArg2*, *bgpArg3*, *bgpArg4*, *bgpArg5*, *bgpArg6*, *bgpArg7*, and *bgpArg8*.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_bgp](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_bgp.html&cp=0_3_1_0_4_16).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`asNum` | Specifies the AS number
`bgpArg1` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **address-family**, **bestpath**, **bgp**, **cluster-id**, **confederation**, **enforce-first-as**, **fast-external-failover**, **graceful-restart**, **graceful-restart-helper**, **log-neighbor-changes**, **maxas-limit**, **neighbor**, **router-id**, **shutdown**, **synchronization**, **timers**, **vrf**.
`bgpArg2` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **ipv4**, **ipv6**, **always-compare-med**, **compare-confed-aspath**, **compare-routerid**, **dont-compare-originator-id**, **tie-break-on-age**, **as-path**, **med**, number of times to prepend the local AS, Route Reflector Cluster ID as a 32 bit quantity or in IP address format, **identifier**, **peers**, delay value, number of autonomous systems in the AS-path attribute, neighbor address, neighbor prefix, manually configured router identifier, keepalive interval.
`bgpArg3` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **aggregate-address**, **client-to-client**, **dampening**, **distance**, **maximum-paths**, **network**, **nexthop**, **redistribute**, **save**, **synchronization**, **ignore**, **multipath-relax**, **confed**, **missing-as-worst**, **non-deterministic**, **remove-recv-med**, **remove-send-med**, set routing domain confederation AS, AS number.
`bgpArg4` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: IP address/prefix length, **route-map**, time after which a penalty is decreased by half, administrative distance to routes outside the AS, **ebgp**, **ibgp**, **synchronization**, IP address, delay value, **direct**, **ospf**, **static**, **memory**.
`bgpArg5` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **as-set**, **summary-only**, name of the route map that controls where BGP route dampening is enabled, value to start reusing a route, administrative distance to routes inside the AS, value for maximum path numbers, **backdoor**, **mask**, **route-map**.
`bgpArg6` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **summary-only**, **as-set**, value to start suppressing a route, administrative distance for local routes, IP subnet address mask, name of the route map.
`bgpArg7` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: maximum duration to suppress a stable route, **route-map**, **backdoor**.
`bgpArg8` | This is an overloaded BGP variable. Please refer to the [cnos_bgp module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_bgp.html?cp=0_3_1_0_2_13) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: time after which an unreachable routes penalty is decreased by half, **backdoor**.
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_bgp.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_bgp_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_bgp_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_bgp_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do BGP configuration
hosts: cnos_bgp_sample
gather_facts: no
connection: local
roles:
- cnos_bgp_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_bgp_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_bgp_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,78 @@
## This contain sample BGP execution tasks
---
- name: Test BGP - neighbor
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}' bgpArg4='{{item.bgpArg4}}' bgpArg5='{{item.bgpArg5}}' bgpArg6='{{item.bgpArg6}}'
with_items: "{{test_bgp_data13}}"
- name: Test BGP - BFD
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}' bgpArg4='{{item.bgpArg4}}'
with_items: "{{test_bgp_data19}}"
- name: Test BGP - address-family - dampening
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}' bgpArg4='{{item.bgpArg4}}' bgpArg5='{{item.bgpArg5}}' bgpArg6='{{item.bgpArg6}}' bgpArg7='{{item.bgpArg7}}' bgpArg8='{{item.bgpArg8}}'
with_items: "{{test_bgp_data1}}"
- name: Test BGP - address-family - network
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}' bgpArg4='{{item.bgpArg4}}' bgpArg5='{{item.bgpArg5}}'
with_items: "{{test_bgp_data18}}"
- name: Test BGP - bestpath - always-compare-med
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data2}}"
- name: Test BGP - bestpath-compare-confed-aspat
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data3}}"
- name: Test BGP - bgp
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data4}}"
- name: Test BGP - cluster-id
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data5}}"
- name: Test BGP - confederation-identifier
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}'
with_items: "{{test_bgp_data6}}"
- name: Test BGP - enforce-first-as
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}'
with_items: "{{test_bgp_data7}}"
- name: Test BGP - fast-external-failover
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}'
with_items: "{{test_bgp_data8}}"
- name: Test BGP - graceful-restart
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data9}}"
- name: Test BGP - graceful-restart-helper
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}'
with_items: "{{test_bgp_data10}}"
- name: Test BGP - maxas-limit
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data11}}"
#- name: Test BGP - neighbor
# cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}'
# with_items: "{{test_bgp_data13}}"
- name: Test BGP - router-id
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}'
with_items: "{{test_bgp_data14}}"
- name: Test BGP - synchronization
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}'
with_items: "{{test_bgp_data15}}"
- name: Test BGP - timers
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}' bgpArg2='{{item.bgpArg2}}' bgpArg3='{{item.bgpArg3}}'
with_items: "{{test_bgp_data16}}"
- name: Test BGP - vrf
cnos_bgp: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_bgp_{{ inventory_hostname }}_output.txt asNum='{{item.asNum}}' bgpArg1='{{item.bgpArg1}}'
with_items: "{{test_bgp_data17}}"
# Completed file

View file

@ -0,0 +1,37 @@
---
test_bgp_data1:
- {asNum: 33, bgpArg1: "address-family", bgpArg2: "ipv4", bgpArg3: "dampening", bgpArg4: 13, bgpArg5: 233, bgpArg6: 333, bgpArg7: 15, bgpArg8: 33 }
test_bgp_data2:
- {asNum: 33, bgpArg1: "bestpath", bgpArg2: "always-compare-med"}
test_bgp_data3:
- {asNum: 33, bgpArg1: "bestpath", bgpArg2: "compare-confed-aspath"}
test_bgp_data4:
- {asNum: 33, bgpArg1: "bgp", bgpArg2: 33}
test_bgp_data5:
- {asNum: 33, bgpArg1: "cluster-id", bgpArg2: "1.2.3.4"}
test_bgp_data6:
- {asNum: 33, bgpArg1: "confederation", bgpArg2: "identifier", bgpArg3: 333}
test_bgp_data7:
- {asNum: 33, bgpArg1: "enforce-first-as"}
test_bgp_data8:
- {asNum: 33, bgpArg1: "fast-external-failover"}
test_bgp_data9:
- {asNum: 33, bgpArg1: "graceful-restart", bgpArg2: 333}
test_bgp_data10:
- {asNum: 33, bgpArg1: "graceful-restart-helper"}
test_bgp_data11:
- {asNum: 33, bgpArg1: "maxas-limit", bgpArg2: 333}
test_bgp_data13:
- {asNum: 33, bgpArg1: "neighbor", bgpArg2: "10.241.107.40", bgpArg3: 13, bgpArg4: "address-family", bgpArg5: "ipv4", bgpArg6: "next-hop-self" }
test_bgp_data14:
- {asNum: 33, bgpArg1: "router-id", bgpArg2: "1.2.3.4"}
test_bgp_data15:
- {asNum: 33, bgpArg1: "synchronization"}
test_bgp_data16:
- {asNum: 33, bgpArg1: "timers", bgpArg2: 333, bgpArg3: 3333}
test_bgp_data17:
- {asNum: 33, bgpArg1: "vrf"}
test_bgp_data18:
- {asNum: 33, bgpArg1: "address-family", bgpArg2: "ipv4", bgpArg3: "network", bgpArg4: "1.2.3.4/5", bgpArg5: "backdoor"}
test_bgp_data19:
- {asNum: 33, bgpArg1: "neighbor", bgpArg2: "10.241.107.40", bgpArg3: 13, bgpArg4: "bfd"}

View file

@ -0,0 +1,110 @@
# Ansible Role: cnos_command_sample - Executing a single CNOS command
---
<add role description below>
This role is an example of using the *cnos_command.py* Lenovo module in the context of CNOS switch configuration. This module allows you to modify the switch running configuration. It provides a way to execute a single CNOS command on a switch by evaluating the current running configuration and executing the command only if the specific setting has not been already configured.
The CNOS command is passed as an argument of the method.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_command](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_command.html&cp=0_3_1_0_4_8).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`clicommand` | Specifies the CLI command as an attribute to this method
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_command.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_command_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_command_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_command_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do some CLI Command configurations
hosts: cnos_command_sample
gather_facts: no
connection: local
roles:
- cnos_command_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_command_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_command_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,7 @@
# This contain sample template execution tasks
---
- name: Test Command
cnos_command: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} clicommand='{{item.clicommand}}' outputfile=./results/cnos_command_{{ inventory_hostname }}_output.txt
with_items: "{{test_runcommand_data1}}"
# Completed file

View file

@ -0,0 +1,3 @@
---
test_runcommand_data1:
- {clicommand: "display users"}

View file

@ -0,0 +1,118 @@
# Ansible Role: cnos_conditional_command_sample - Executing a single CNOS command with respect to conditions specified in the inventory
---
<add role description below>
This role is an example of using the *cnos_conditional_command.py* Lenovo module in the context of CNOS switch configuration. This module allows you to modify the running configuration of a switch. It provides a way to execute a single CNOS command on a network device by evaluating the current running configuration and executing the command only if the specific settings have not been already configured.
The CNOS command is passed as an argument of the method.
This module functions the same as the *cnos_command.py* module. The only exception is that the following inventory variable can be specified: condition = <flag string>
When this inventory variable is specified as the variable of a task, the command is executed for the network element that matches the flag string.
Usually, commands are executed across a group of network devices. When there is a requirement to skip the execution of the command on one or more devices, it is recommended to use this module.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_conditional_command](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_conditional_command.html&cp=0_3_1_0_4_9).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
`condition` | If `condition=false` is specified in the inventory file against any device, the command execution is skipped for that device (**true**, **false**)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`flag` | If a task needs to be executed, the flag needs to be set the same as it is specified in the inventory for that device
`clicommand` | Specifies the CLI command as an attribute to this method
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_conditional_command.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_conditional_command_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_conditional_command_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos condition=pass
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_conditional_command_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do some configurations
hosts: cnos_conditional_command_sample
gather_facts: no
connection: local
roles:
- cnos_conditional_command_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_conditional_command_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_conditional_command_sample]
10.241.107.39 username=<username> password=<password> condition=pass deviceType=g8272_cnos

View file

@ -0,0 +1,7 @@
# This contain sample command execution tasks
---
- name: Run a command
cnos_conditional_command: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} condition={{ hostvars[inventory_hostname]['condition'] }} flag='{{item.flag}}' clicommand='{{item.clicommand}}' outputfile=./results/cnos_conditional_command_{{ inventory_hostname }}_output.txt
with_items: "{{conditional_command_data1}}"
# Completed file

View file

@ -0,0 +1,3 @@
---
conditional_command_data1:
- {flag: "pass", clicommand: "display users"}

View file

@ -0,0 +1,118 @@
# Ansible Role: cnos_conditional_template_sample - Manages switch configuration using templates with respect to conditions specified in the inventory
---
<add role description below>
This role is an example of using the *cnos_conditional_template.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with the running configuration of a switch. It provides a way to execute a set of CNOS commands on a switch by evaluating the current running configuration and executing the commands only if the specific settings have not been already configured.
The configuration source can be a set of commands or a template written in the Jinja2 templating language.
This module functions the same as the *cnos_template.py* module. The only exception is that the following inventory variable can be specified: condition = <flag string>
When this inventory variable is specified as the variable of a task, the template is executed for the network element that matches the flag string.
Usually, templates are used when commands are the same across a group of network devices. When there is a requirement to skip the execution of the template on one or more devices, it is recommended to use this module.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_conditional_template](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_conditional_template.html&cp=0_3_1_0_4_11).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
`condition` | If `condition=<flag string>` is specified in the inventory file against any device, the template execution is done for that device in case it matches the flag setting for that task
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`flag` | If a task needs to be executed, you have to set the flag the same as it is specified in the inventory for that device
`commandfile` | Specifies the path to the CNOS command file which needs to be applied
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_conditional_template.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_conditional_template_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_conditional_template_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos condition=pass
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_conditional_template_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do some template configurations
hosts: cnos_conditional_template_sample
gather_facts: no
connection: local
roles:
- cnos_conditional_template_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_conditional_template_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_conditional_template_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos condition=pass

View file

@ -0,0 +1,11 @@
# This contain sample conditional template execution tasks
---
- name: Replace Config CLI command template with values
template: src=demo_template.j2 dest=./commands/cnos_conditional_template_{{ inventory_hostname }}_command.txt
with_items: "{{conditional_template_data1}}"
- name: Applying CLI commands on Switches
cnos_conditional_template: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}}
condition={{ hostvars[inventory_hostname]['condition'] }} flag='{{item.flag}}' commandfile=./commands/cnos_conditional_template_{{ inventory_hostname }}_command.txt outputfile=./results/cnos_conditional_template_{{ inventory_hostname }}_output.txt
with_items: "{{conditional_template_data1}}"
# Completed file

View file

@ -0,0 +1,14 @@
#Demo Template
vlan {{item.vlanid1}}
exit
config d
interface ethernet {{item.slot_chassis_number1}}
aggregation-group {{item.portchannel_interface_number1}} mode {{item.portchannel_mode1}}
exit
config d
interface port-aggregation {{item.portchannel_interface_number1}}
shut
lacp suspend-individual
no shut
exit

View file

@ -0,0 +1,3 @@
---
conditional_template_data1:
- {flag: "pass", vlanid1: 13, slot_chassis_number1: "1/2", portchannel_interface_number1: 100, portchannel_mode1: "active"}

View file

@ -0,0 +1,118 @@
# Ansible Role: cnos_ethernet_sample - Performs switch ethernet port configuration and state management
---
<add role description below>
This role is an example of using the *cnos_interface.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with interface related configurations. The operators used are overloaded to ensure control over switch interface configurations, such as ethernet ports, loopback interfaces, VLANs, and the management interface.
Apart from the regular device connection related attributes, there are seven interface arguments that will perform further configurations. They are *interfaceArg1*, *interfaceArg2*, *interfaceArg3*, *interfaceArg4*, *interfaceArg5*, *interfaceArg6*, and *interfaceArg7*.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_interface](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_interface.html&cp=0_3_1_0_4_12).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`interfaceOption` | Specifies the type of the interface that will be configured (**ethernet** - ethernet port, **loopback** - loopback interface, **vlan** - VLAN, **mgmt** - management interface, **port-aggregation** - Link Aggregation Group)
`interfaceRange` | Specifies the interface range that will be configured
`interfaceArg1` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **aggregation-group**, **bfd**, **bridge-port**, **description**, **duplex**, **flowcontrol**, **ip**, **ipv6**, **lacp**, **lldp**, **load-interval**, **mac**, **mac-address**, **mac-learn**, **microburst-detection**, **mtu**, **service**, **service-policy**, **shutdown**, **snmp**, **spanning-tree**, **speed**, **storm-control**, **vlan**, **vrrp**, **port-aggregation**.
`interfaceArg2` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: specify a LAG number, **authentication**, **echo**, **ipv4**, **ipv6**, **interval**, **neighbor**, **access**, **mode**, **trunk**, interface description, **auto**, **full**, **half**, **receive**, **send**, **access-group**, **arp**, **dhcp**, **port**, **port-unreachable**, **redirects**, **router**, **unreachables**, **address**, **link-local**, **port-priority**, **suspend-individual**, **timeout**, **transmit**, **trap-notification**, **tlv-select**, load interval delay, **counter**, name for the MAC access group, MAC address in XXXX.XXXX.XXXX format, threshold value, MTU in bytes, instance ID to map to the EVC, **input**, **output**, **copp-system-policy**, **type**, **bpdufilter**, **bpduguard**, **cost**, **enable**, **disable**, **guard**, **link-type**, **mst**, **port**, **port-priority**, **vlan**, **auto**, 1000, 10000, 40000, **broadcast**, **unicast**, **multicast**, **egress-only**, **destination-ip**, **destination-mac**, **destination-port**, **source-dest-ip**, **source-dest-mac**, **source-dest-port**, **source-interface**, **source-ip**, **source-mac**, **source-port**.
`interfaceArg3` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **active**, **passive**, **on**, **keyed-md5**, **keyed-sha1**, **meticulous-keyed-md5**, **meticulous-keyed-sha1**, **simple**, **authentication**, **echo**, **interval**, interval value, source IP address, **off**, ACL name, IP address of the ARP entry, **timeout**, **client**, **relay**, **area**, **multi-area**, **dhcp**, IPv6 address, IPv6 address of the DHCP Relay, Neighbor IPv6 address, LACP port priority, **long**, **short**, **link-aggregation**, **mac-phy-status**, **management-address**, **max-frame-size**, **port-description**, **port-protocol-vlan**, **port-vlan**, **power-mdi**, **protocol-identity**, **system-capabilities**, **system-description**, **system-name**, **vid-management**, **vlan-name**, counter for the load interval, name of the policy to attach, **all**, COPP class name to attach, **qos**, **queuing**, **enable**, **disable**, **auto**, port path cost, **loop**, **root**, **auto**, **point-to-point**, **shared**, MSTP instance range, port priority value, specify VLAN, allowed traffic level, **ipv6**, **source-interface**.
`interfaceArg4` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **key-chain**, **key-id**, **keyed-md5**, **keyed-sha1**, **meticulous-keyed-md5**, **meticulous-keyed-sha1**, **simple**, interval value, BFD minimum receive interval, destination IP address, **in**, **out**, MAC address in XXXX.XXXX.XXXX format, timeout value, **class-id**, **request**, IPv4 address of the DHCP Relay, OSPF area ID, **anycast**, **secondary**, **ethernet**, **vlan**, load interval delay, name of the QoS policy to attach, **input**, **output**, **cost**, **port-priority**.
`interfaceArg5` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: name of the key chain, key ID, **key-chain**, **key-id**, BFD minimum receive interval, Hello multiplier value, **admin-down**, **multihop**, **non-persistent**, vendor class ID name, **bootfile-name**, **host-name**, **log-server**, **ntp-server**, **tftp-server-name**, specifiy ethernet port, specify VLAN, name of the QoS policy to attach, **auto**, port path cost, port priority value.
`interfaceArg6` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: authentication key string, name of the key chain, key ID, Hello multiplier value, **admin-down**, **non-persistent**.
`interfaceArg7` | This is an overloaded BGP variable. Please refer to the [cnos_interface module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_interface.html?cp=0_3_1_0_2_12) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: authentication key string, **admin-down**.
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_interface.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_interface_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_ethernet_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_interface_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do Interface Ethernet configurations
hosts: cnos_ethernet_sample
gather_facts: no
connection: local
roles:
- cnos_ethernet_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_ethernet_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_ethernet_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,98 @@
### This contain sample execution tasks
---
- name: Test Interface Ethernet - aggregation-group
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data1}}"
#- name: Test Interface Ethernet - aggregation-group - Interface Range
# cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
# with_items: "{{test_ethernet_data24}}"
- name: Test Interface Ethernet - bridge-port
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data2}}"
- name: Test Interface Ethernet - bridgeport mode
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data3}}"
- name: Test Interface Ethernet - Description
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_ethernet_data4}}"
- name: Test Interface Ethernet - Duplex
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_ethernet_data5}}"
- name: Test Interface Ethernet - flowcontrol
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data6}}"
- name: Test Interface Ethernet - lacp
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data7}}"
- name: Test Interface Ethernet - lldp
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data8}}"
- name: Test Interface Ethernet - load-interval
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}'
with_items: "{{test_ethernet_data9}}"
#- name: Test Interface Ethernet - mac
# cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
# with_items: "{{test_ethernet_data10}}"
- name: Test Interface Ethernet - microburst-detection
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_ethernet_data11}}"
- name: Test Interface Ethernet - mtu
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_ethernet_data12}}"
- name: Test Interface Ethernet - service-policy
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data13}}"
- name: Test Interface Ethernet - speed
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_ethernet_data14}}"
- name: Test Interface Ethernet - storm
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data15}}"
#- name: Test Interface Ethernet - vlan
# cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
# with_items: "{{test_ethernet_data16}}"
- name: Test Interface Ethernet - vrrp
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_ethernet_data17}}"
- name: Test Interface Ethernet - spanning tree1
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data18}}"
- name: Test Interface Ethernet - spanning tree 2
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}' interfaceArg5='{{item.interfaceArg5}}'
with_items: "{{test_ethernet_data19}}"
- name: Test Interface Ethernet - ip1
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}'
with_items: "{{test_ethernet_data20}}"
- name: Test Interface Ethernet - ip2
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_ethernet_data21}}"
- name: Test Interface Ethernet - bfd
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}' interfaceArg5='{{item.interfaceArg5}}'
with_items: "{{test_ethernet_data22}}"
- name: Test Interface Ethernet - bfd
cnos_interface: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_ethernet_{{ inventory_hostname }}_output.txt interfaceOption='{{item.interfaceOption}}' interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}' interfaceArg5='{{item.interfaceArg5}}' interfaceArg6='{{item.interfaceArg6}}'
with_items: "{{test_ethernet_data23}}"
# Completed file

View file

@ -0,0 +1,49 @@
---
test_ethernet_data1:
- {interfaceOption: 'ethernet', interfaceRange: 1, interfaceArg1: "aggregation-group", interfaceArg2: 33, interfaceArg3: "on"}
test_ethernet_data2:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "bridge-port", interfaceArg2: "access", interfaceArg3: 33}
test_ethernet_data3:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "bridge-port", interfaceArg2: "mode", interfaceArg3: "access"}
test_ethernet_data4:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "description", interfaceArg2: "Hentammoo "}
test_ethernet_data5:
- {interfaceOption: 'ethernet', interfaceRange: 1, interfaceArg1: "duplex", interfaceArg2: "auto"}
test_ethernet_data6:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "flowcontrol", interfaceArg2: "send", interfaceArg3: "off"}
test_ethernet_data7:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "lacp", interfaceArg2: "port-priority", interfaceArg3: 33}
test_ethernet_data8:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "lldp", interfaceArg2: "tlv-select", interfaceArg3: "max-frame-size"}
test_ethernet_data9:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "load-interval", interfaceArg2: "counter", interfaceArg3: 2, interfaceArg4: 33}
test_ethernet_data10:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "mac", interfaceArg2: "copp-system-acl-vlag-hc"}
test_ethernet_data11:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "microburst-detection", interfaceArg2: 25}
test_ethernet_data12:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "mtu", interfaceArg2: 66}
test_ethernet_data13:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "service-policy", interfaceArg2: "input", interfaceArg3: "Anil"}
test_ethernet_data14:
- {interfaceOption: 'ethernet', interfaceRange: 1, interfaceArg1: "speed", interfaceArg2: "auto"}
test_ethernet_data15:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "storm-control", interfaceArg2: "broadcast", interfaceArg3: 12.5 }
test_ethernet_data16:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "vlan", interfaceArg2: "disable"}
test_ethernet_data17:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "vrrp", interfaceArg2: 33}
test_ethernet_data18:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "spanning-tree", interfaceArg2: "bpduguard", interfaceArg3: "enable"}
test_ethernet_data19:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "spanning-tree", interfaceArg2: "mst", interfaceArg3: "33-35", interfaceArg4: "cost", interfaceArg5: 33}
test_ethernet_data20:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "ip", interfaceArg2: "access-group", interfaceArg3: "anil", interfaceArg4: "in"}
test_ethernet_data21:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "ip", interfaceArg2: "port", interfaceArg3: "anil" }
test_ethernet_data22:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "bfd", interfaceArg2: "interval", interfaceArg3: 55, interfaceArg4: 55, interfaceArg5: 33}
test_ethernet_data23:
- {interfaceOption: 'ethernet', interfaceRange: 33, interfaceArg1: "bfd", interfaceArg2: "ipv4", interfaceArg3: "authentication", interfaceArg4: "meticulous-keyed-md5", interfaceArg5: "key-chain", interfaceArg6: "mychain"}
test_ethernet_data24:
- {interfaceOption: 'ethernet', interfaceRange: "1/1-2", interfaceArg1: "aggregation-group", interfaceArg2: 33, interfaceArg3: "on"}

View file

@ -0,0 +1,94 @@
# Ansible Role: cnos_facts_sample - Displays switch inforamtion
---
<add role description below>
This role is an example of using the *cnos_facts.py* Lenovo module in the context of CNOS switch configuration. This module allows you to view the switch information. It executes the **display sys-info** CLI command on a switch and returns a file containing all the system information of the target network device.
The results of the operation can be viewed in results directory.
For more details, see [Lenovo modules for Ansible: cnos_facts](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_facts.html&cp=0_3_1_0_4_0).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_facts.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_facts_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_facts_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_facts_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do Show Sys Info
hosts: cnos_facts_sample
gather_facts: no
connection: local
roles:
- cnos_facts_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_facts_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_facts_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,7 @@
# This contain sample show sys info tasks
---
- name: Test Sys Info
cnos_facts: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} enablePassword='{{item.enablePassword}}' outputfile=./results/cnos_facts_{{ inventory_hostname }}_output.txt
with_items: "{{test_showsysinfo_data}}"
# Completed file

View file

@ -0,0 +1,3 @@
---
test_showsysinfo_data:
- {enablePassword: "anil"}

View file

@ -0,0 +1,117 @@
# Ansible Role: cnos_image_sample - Switch firmware download from a remote server
---
<add role description below>
This role is an example of using the *cnos_image.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with switch firmware images. It provides a way to download a firmware image to a network device from a remote server using FTP, SFTP, TFTP, or SCP.
The first step is to create a directory from where the remote server can be reached. The next step is to provide the full file path of the images location. Authentication details required by the remote server must be provided as well.
By default, this method makes the newly downloaded firmware image the active image, which will be used by the switch during the next restart.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_image](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_image.html&cp=0_3_1_0_4_2).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`imgType` | Specifies the firmware image type to be downloaded (**all** - both Uboot and OS images, **boot** - only the Uboot image, **os** - only the OS image, **onie** - ONIE image)
`protocol` | Specifies the protocol used by the network device to interact with the remote server from where to download the firmware image (**ftp** - FTP, **sftp** - SFTP, **tftp** - TFTP, **scp** - SCP)
`serverip` | Specifies the IP Address of the remote server from where the software image will be downloaded
`imgpath` | Specifies the full file path of the image located on the remote server (in case the relative path is used as the variable value, the root folder for the user of the server needs to be specified)
`serverusername` | Configures the username for the server relating to the protocol used
`serverpassword` | Configures the password for the server relating to the protocol used
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_image.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_image_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_image_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_image_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do image download
hosts: cnos_image_sample
gather_facts: no
connection: local
roles:
- cnos_image_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,17 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_image_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_image_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos imgpath=/root/cnos_images/G8272-10.1.0.112.img
#Use this in case its TFTP as tftpboot is the starting point for tftp
#10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos imgpath="/anil/G8272-10.2.0.34.img

View file

@ -0,0 +1,16 @@
# This contain sample Image download tasks
---
- name: Test Image transfer
cnos_image: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_image_{{ inventory_hostname }}_output.txt protocol='{{item.protocol}}' serverip='{{item.serverip}}' imgpath={{ hostvars[inventory_hostname]['imgpath']}} imgtype='{{item.imgtype}}' serverusername='{{item.serverusername}}' serverpassword='{{item.serverpassword}}'
with_items: "{{test_image_data1}}"
#Root folder will be different for SFTP/SCP and TFTP
#The following task is commented.
#Before trying this, please change in /etc/ansible/hosts file
#and place an image with reference to your tftp-root folder
#- name: Test Image tftp
# cnos_image: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_image_{{ inventory_hostname }}_output.txt protocol='{{item.protocol}}' serverip='{{item.serverip}}' imgpath={{ hostvars[inventory_hostname]['imgpath']}} imgtype='{{item.imgtype}}'
# with_items: "{{test_image_data2}}"
# Completed file

View file

@ -0,0 +1,6 @@
---
test_image_data1:
- {protocol: "sftp", serverip: "10.241.106.118", imgtype: "os", serverusername: "root", serverpassword: "root123"}
test_image_data2:
- {protocol: "tftp", serverip: "10.241.106.118", imgtype: "os"}

View file

@ -0,0 +1,115 @@
# Ansible Role: cnos_portchannel_sample - Switch Link Aggregation Group (LAG) configuration
---
<add role description below>
This role is an example of using the *cnos_portchannel.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with port aggregation related configurations. The operators used are overloaded to ensure control over switch port aggregation configurations.
Apart from the regular device connection related attributes, there are five vLAG arguments which are overloaded variables that will perform further configurations. They are portChArg1, portChArg2, portChArg3, portChArg4, and portChArg5.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_portchannel](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_portchannel.html&cp=0_3_1_0_4_13).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`interfaceRange` | Specifies the interface range that will be part of the LAG
`portChArg1` | This is an overloaded BGP variable. Please refer to the [cnos_portchannel module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_portchannel.html?cp=0_3_1_0_2_14) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **aggregation-group**, **bridge-port**, **description**, **duplex**, **flowcontrol**, **lacp**, **lldp**, **load-interval**, **mac**, **mac-address**, **mac-learn**, **microburst-detection**, **mtu**, **service**, **service-policy**, **shutdown**, **snmp**, **speed**, **storm-control**, **vlan**, **vrrp**, **port-aggregation**.
`portChArg2` | This is an overloaded BGP variable. Please refer to the [cnos_portchannel module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_portchannel.html?cp=0_3_1_0_2_14) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: specify a LAG number, **access**, **mode**, **trunk**, LAG description, **auto**, **full**, **half**, **receive**, **send**, **port-priority**, **suspend-individual**, **timeout**, **transmit**, **trap-notification**, **tlv-select**, load interval delay, **counter**, name for the MAC access group, MAC address in XXXX.XXXX.XXXX format, threshold value, MTU in bytes, instance ID to map to the EVC, **input**, **output**, **copp-system-policy**, **type**, **auto**, 1000, 10000, 40000, **broadcast**, **unicast**, **multicast**, **disable**, **enable**, **egress-only**, virtual router ID, **destination-ip**, **destination-mac**, **destination-port**, **source-dest-ip**, **source-dest-mac**, **source-dest-port**, **source-interface**, **source-ip**, **source-mac**, **source-port**.
`portChArg3` | This is an overloaded BGP variable. Please refer to the [cnos_portchannel module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_portchannel.html?cp=0_3_1_0_2_14) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **active**, **passive**, **on**, **off**, LACP port priority, **long**, **short**, **link-aggregation**, **mac-phy-status**, **management-address**, **max-frame-size**, **port-description**, **port-protocol-vlan**, **port-vlan**, **power-mdi**, **protocol-identity**, **system-capabilities**, **system-description**, **system-name**, **vid-management**, **vlan-name**, counter for the load interval, the name of the policy to attach, **all**, COPP class name to attach, **qos**, **queuing**, allowed traffic level, **ipv6**, **source-interface**.
`portChArg4` | This is an overloaded BGP variable. Please refer to the [cnos_portchannel module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_portchannel.html?cp=0_3_1_0_2_14) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: load interval delay, name of the QoS policy to attach, **input**, **output**
`portChArg5` | This is an overloaded BGP variable. Please refer to the [cnos_portchannel module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_portchannel.html?cp=0_3_1_0_2_14) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: name of the QoS policy to attach
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_portchannel.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_portchannel_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_portchannel_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_portchannel_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do Port Channel configurations
hosts: cnos_portchannel_sample
gather_facts: no
connection: local
roles:
- cnos_portchannel_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_portchannel_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_portchannel_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,98 @@
# This contain sample template execution tasks
---
- name: Test Port Channel - aggregation-group
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data1}}"
- name: Test Port Channel - aggregation-group - Interface Range
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data24}}"
- name: Test Port Channel - bridge-port
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data2}}"
- name: Test Port Channel - bridgeport mode
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data3}}"
- name: Test Port Channel - Description
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_portchannel_data4}}"
- name: Test Port Channel - Duplex
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_portchannel_data5}}"
- name: Test Port Channel - flowcontrol
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data6}}"
- name: Test Port Channel - lacp
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data7}}"
- name: Test Port Channel - lldp
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data8}}"
- name: Test Port Channel - load-interval
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}'
with_items: "{{test_portchannel_data9}}"
#- name: Test Port Channel - mac
# cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
# with_items: "{{test_portchannel_data10}}"
- name: Test Port Channel - microburst-detection
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_portchannel_data11}}"
- name: Test Port Channel - mtu
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_portchannel_data12}}"
- name: Test Port Channel - service-policy
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data13}}"
- name: Test Port Channel - speed
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_portchannel_data14}}"
- name: Test Port Channel - storm
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data15}}"
#- name: Test Port Channel - vlan
# cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
# with_items: "{{test_portchannel_data16}}"
- name: Test Port Channel - vrrp
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}'
with_items: "{{test_portchannel_data17}}"
- name: Test Port Channel - spanning tree1
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data18}}"
- name: Test Port Channel - spanning tree 2
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}' interfaceArg5='{{item.interfaceArg5}}'
with_items: "{{test_portchannel_data19}}"
- name: Test Port Channel - ip1
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}'
with_items: "{{test_portchannel_data20}}"
- name: Test Port Channel - ip2
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}'
with_items: "{{test_portchannel_data21}}"
- name: Test Port Channel - bfd
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}' interfaceArg5='{{item.interfaceArg5}}'
with_items: "{{test_portchannel_data22}}"
- name: Test Port Channel - bfd
cnos_portchannel: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_portchannel_{{ inventory_hostname }}_output.txt interfaceRange='{{item.interfaceRange}}' interfaceArg1='{{item.interfaceArg1}}' interfaceArg2='{{item.interfaceArg2}}' interfaceArg3='{{item.interfaceArg3}}' interfaceArg4='{{item.interfaceArg4}}' interfaceArg5='{{item.interfaceArg5}}' interfaceArg6='{{item.interfaceArg6}}'
with_items: "{{test_portchannel_data23}}"
## Completed file

View file

@ -0,0 +1,49 @@
---
test_portchannel_data1:
- {interfaceRange: 33, interfaceArg1: "aggregation-group", interfaceArg2: 33, interfaceArg3: "on"}
test_portchannel_data2:
- {interfaceRange: 33, interfaceArg1: "bridge-port", interfaceArg2: "access", interfaceArg3: 33}
test_portchannel_data3:
- {interfaceRange: 33, interfaceArg1: "bridge-port", interfaceArg2: "mode", interfaceArg3: "access"}
test_portchannel_data4:
- {interfaceRange: 33, interfaceArg1: "description", interfaceArg2: "Hentammoo "}
test_portchannel_data5:
- {interfaceRange: 2, interfaceArg1: "duplex", interfaceArg2: "auto"}
test_portchannel_data6:
- {interfaceRange: 33, interfaceArg1: "flowcontrol", interfaceArg2: "send", interfaceArg3: "off"}
test_portchannel_data7:
- {interfaceRange: 33, interfaceArg1: "lacp", interfaceArg2: "port-priority", interfaceArg3: 33}
test_portchannel_data8:
- {interfaceRange: 33, interfaceArg1: "lldp", interfaceArg2: "tlv-select", interfaceArg3: "max-frame-size"}
test_portchannel_data9:
- {interfaceRange: 33, interfaceArg1: "load-interval", interfaceArg2: "counter", interfaceArg3: 2, interfaceArg4: 33 }
test_portchannel_data10:
- {interfaceRange: 33, interfaceArg1: "mac", interfaceArg2: "copp-system-acl-vlag-hc"}
test_portchannel_data11:
- {interfaceRange: 33, interfaceArg1: "microburst-detection", interfaceArg2: 25}
test_portchannel_data12:
- {interfaceRange: 33, interfaceArg1: "mtu", interfaceArg2: 66}
test_portchannel_data13:
- {interfaceRange: 33, interfaceArg1: "service-policy", interfaceArg2: "input", interfaceArg3: "Anil"}
test_portchannel_data14:
- {interfaceRange: 13, interfaceArg1: "speed", interfaceArg2: "auto"}
test_portchannel_data15:
- {interfaceRange: 33, interfaceArg1: "storm-control", interfaceArg2: "broadcast", interfaceArg3: 12.5 }
test_portchannel_data16:
- {interfaceRange: 33, interfaceArg1: "vlan", interfaceArg2: "disable"}
test_portchannel_data17:
- {interfaceRange: 33, interfaceArg1: "vrrp", interfaceArg2: 33}
test_portchannel_data18:
- {interfaceRange: 33, interfaceArg1: "spanning-tree", interfaceArg2: "bpduguard", interfaceArg3: "enable"}
test_portchannel_data19:
- {interfaceRange: 33, interfaceArg1: "spanning-tree", interfaceArg2: "mst", interfaceArg3: "33-35", interfaceArg4: "cost", interfaceArg5: 33}
test_portchannel_data20:
- {interfaceRange: 33, interfaceArg1: "ip", interfaceArg2: "access-group", interfaceArg3: "anil", interfaceArg4: "in"}
test_portchannel_data21:
- {interfaceRange: 33, interfaceArg1: "ip", interfaceArg2: "port", interfaceArg3: "anil" }
test_portchannel_data22:
- {interfaceRange: 33, interfaceArg1: "bfd", interfaceArg2: "interval", interfaceArg3: 55, interfaceArg4: 55, interfaceArg5: 33}
test_portchannel_data23:
- {interfaceRange: 33, interfaceArg1: "bfd", interfaceArg2: "ipv4", interfaceArg3: "authentication", interfaceArg4: "meticulous-keyed-md5", interfaceArg5: "key-chain", interfaceArg6: "mychain"}
test_portchannel_data24:
- {interfaceRange: "1/1-2", interfaceArg1: "aggregation-group", interfaceArg2: 33, interfaceArg3: "on"}

View file

@ -0,0 +1,117 @@
# Ansible Role: cnos_rollback_sample - Rolls back the configuration of a switch from a remote server
---
<add role description below>
This role is an example of using the *cnos_rollback.py* Lenovo module in the context of CNOS switch configuration.This module allows you to work with switch configurations. It provides a way to roll back configurations of a switch from a remote server. This is achieved by using startup or running configurations of the target device that were previously backed up to a remote server using FTP, SFTP, TFTP, or SCP.
The first step is to create a directory from where the remote server can be reached. The next step is to provide the full file path of the backup configurations location. Authentication details required by the remote server must be provided as well.
By default, this method overwrites the switchs configuration file with the newly downloaded file.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_rollback](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_rollback.html&cp=0_3_1_0_4_5).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`configType` | Specifies the type of configuration which will be used for the rolling back process (**running-config** - running configuration, **startup-config** - startup configuration)
`protocol` | Specifies the protocol used by the network device to interact with the remote server from where to download the backup configuration (**ftp** - FTP, **sftp** - SFTP, **tftp** - TFTP, **scp** - SCP)
`serverip` | Specifies the IP Address of the remote server from where the backup configuration will be downloaded
`rcpath` | Specifies the full file path where the configuration file located on the remote server (in case the relative path is used as the variable value, the root folder for the user of the server needs to be specified)
`serverusername` | Configures the username for the server relating to the protocol used
`serverpassword` | Configures the password for the server relating to the protocol used
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_rollback.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_rollback_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_rollback_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_rollback_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do rollback of configurations
hosts: cnos_rollback_sample
gather_facts: no
connection: local
roles:
- cnos_rollback_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,18 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_rollback_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_rollback_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos rcpath=/root/cnos_config/G8272-running-config.txt
#Use this in case its TFTP as tftpboot folder is the starting point for tftp
#10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos rcpath=/anil/G8272-running-config.txt

View file

@ -0,0 +1,25 @@
# This contain sample config Roll Back execution tasks
---
- name: Test Rollback of config - Running config
cnos_rollback: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_rollback_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}} serverusername='{{item.serverusername}}' serverpassword='{{item.serverpassword}}'
with_items: "{{test_rollback_data1}}"
- name: Test Rollback of config - Startup config
cnos_rollback: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_rollback_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}} serverusername='{{item.serverusername}}' serverpassword='{{item.serverpassword}}'
with_items: "{{test_rollback_data2}}"
#Root folder will be different for SFTP/SCP and TFTP
#The following task is commented.
#Before trying this, please change in /etc/ansible/hosts file
#and place an config file with reference to your tftp-root folder
#- name: Test Rollback of config - Running config - TFTP
# cnos_rollback: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_rollback_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}}
# with_items: "{{test_rollback_data3}}"
#- name: Test Rollback of config - Startup config - TFTP
# cnos_rollback: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_rollback_{{ inventory_hostname }}_output.txt configType='{{item.configType}}' protocol='{{item.protocol}}' serverip='{{item.serverip}}' rcpath={{ hostvars[inventory_hostname]['rcpath']}}
# with_items: "{{test_rollback_data4}}"
# Completed file

View file

@ -0,0 +1,12 @@
---
test_rollback_data1:
- {configType: running-config, protocol: "sftp", serverip: "10.241.106.118", serverusername: "root", serverpassword: "root123"}
test_rollback_data2:
- {configType: startup-config, protocol: "sftp", serverip: "10.241.106.118", serverusername: "root", serverpassword: "root123"}
test_rollback_data3:
- {configType: running-config, protocol: "tftp", serverip: "10.241.106.118"}
test_rollback_data4:
- {configType: startup-config, protocol: "tftp", serverip: "10.241.106.118"}

View file

@ -0,0 +1,94 @@
# Ansible Role: cnos_save_sample - Saving the switch running configuration
---
<add role description below>
This role is an example of using the *cnos_save.py* Lenovo module in the context of CNOS switch configuration. This module allows you to copy the running configuration of a switch over its startup configuration. It is recommended to use this module shortly after any major configuration changes so they persist after a switch restart.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_save](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_save.html&cp=0_3_1_0_4_3).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_save.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_save_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_save_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_save_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do save configurations
hosts: cnos_save_sample
gather_facts: no
connection: local
roles:
- cnos_save_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_save_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_save_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,18 @@
# This contain sample template execution tasks
---
- name: Test Save
cnos_save: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_save_{{ inventory_hostname }}_output.txt
with_items: "{{cnos_save_data1}}"
- name: Test Reset to factory
cnos_factory: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_save_{{ inventory_hostname }}_output.txt
with_items: "{{cnos_save_data2}}"
- name: Test Again save
cnos_save: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_save_{{ inventory_hostname }}_output.txt
with_items: "{{cnos_save_data3}}"
- name: Test Reload
cnos_reload: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_save_{{ inventory_hostname }}_output.txt
with_items: "{{cnos_save_data4}}"
# Completed file

View file

@ -0,0 +1,9 @@
---
cnos_save_data1:
- {}
cnos_save_data2:
- {}
cnos_save_data3:
- {}
cnos_save_data4:
- {}

View file

@ -0,0 +1,94 @@
# Ansible Role: cnos_showrun_sample - Displays Running Configuration inforamtion
---
<add role description below>
This role is an example of using the *cnos_showrun.py* Lenovo module in the context of CNOS switch configuration. This module allows you to view the switch information. It executes the **display running-config** CLI command on a switch and returns a file containing all the system information of the target network device.
The results of the operation can be viewed in results directory.
For more details, see [Lenovo modules for Ansible: cnos_showrun](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_showrun.html&cp=0_3_1_0_4_0).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_showrun.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_showrun_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The hosts file for the role is located in the main directory of the role.
```
[cnos_showrun_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_showrun_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do Show Sys Info
hosts: cnos_showrun_sample
gather_facts: no
connection: local
roles:
- cnos_showrun_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_facts_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_showrun_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,6 @@
# This contain sample show rnunning config tasks
---
- name: Test Running Configurations
cnos_showrun: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} enablePassword='{{item.enablePassword}}' outputfile=./results/cnos_showrun_{{ inventory_hostname }}_output.txt
with_items: "{{test_showrun_data}}"
# Completed file

View file

@ -0,0 +1,3 @@
---
test_showrun_data:
- {enablePassword: "anil"}

View file

@ -0,0 +1,110 @@
# Ansible Role: cnos_template_sample - Manages switch configuration using templates
---
<add role description below>
This role is an example of using the *cnos_template.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with the running configuration of a switch. It provides a way to execute a set of CNOS commands on a switch by evaluating the current running configuration and executing the commands only if the specific settings have not been already configured.
The configuration source can be a set of commands or a template written in the Jinja2 templating language.#
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_template](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_template.html&cp=0_3_1_0_4_10).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`commandfile` | Specifies the path to the CNOS command file which needs to be applied
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_template.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_template_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_template_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_template_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do some template configurations
hosts: cnos_template_sample
gather_facts: no
connection: local
roles:
- cnos_template_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_template_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_template_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,10 @@
# This contain sample template execution tasks
---
- name: Replace Config CLI command template with values
template: src=demo_template.j2 dest=./commands/cnos_template_{{ inventory_hostname }}_commands.txt
with_items: "{{cnos_template_data}}"
- name: Applying CLI commands on Switches
cnos_template: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} commandfile=./commands/cnos_template_{{ inventory_hostname }}_commands.txt outputfile=./results/cnos_template_{{ inventory_hostname }}_output.txt
with_items: "{{cnos_template_data}}"
# Completed file

View file

@ -0,0 +1,14 @@
#Demo Template
vlan {{item.vlanid1}}
exit
config d
interface ethernet {{item.slot_chassis_number1}}
aggregation-group {{item.portchannel_interface_number1}} mode {{item.portchannel_mode1}}
exit
config d
interface port-aggregation {{item.portchannel_interface_number1}}
shut
lacp suspend-individual
no shut
exit

View file

@ -0,0 +1,3 @@
---
cnos_template_data:
- {vlanid1: 13, slot_chassis_number1: "1/2", portchannel_interface_number1: 100, portchannel_mode1: "active"}

View file

@ -0,0 +1,113 @@
# Ansible Role: cnos_vlag_sample - Switch vLAG configuration
---
<add role description below>
This role is an example of using the *cnos_vlag.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with virtual Link Aggregation Groups (vLAG) related configurations. The operators used are overloaded to ensure control over switch vLAG configurations.
Apart from the regular device connection related attributes, there are four vLAG arguments which are overloaded variables that will perform further configurations. They are *vlagArg1*, *vlagArg2*, *vlagArg3*, and *vlagArg4*.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_vlag](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_vlag.html&cp=0_3_1_0_4_15).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`vlagArg1` | This is an overloaded BGP variable. Please refer to the [cnos_vlag module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_template.html?cp=0_3_1_0_2_10) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **enable**, **auto-recovery**, **config-consistency**, **isl**, **mac-address-table**, **peer-gateway**, **priority**, **startup-delay**, **tier-id**, **vrrp**, **instance**, **hlthchk**.
`vlagArg2` | This is an overloaded BGP variable. Please refer to the [cnos_vlag module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_template.html?cp=0_3_1_0_2_10) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: auto-recovery interval, **disabled**, **strict**, port aggregation number, vLAG priority, delay time, vLAG tier ID value, vLAG instance number, **keepalive-attempts**, **keepalive-interval**, **retry-interval**, **peer-ip**.
`vlagArg3` | This is an overloaded BGP variable. Please refer to the [cnos_vlag module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_template.html?cp=0_3_1_0_2_10) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **enable**, **port-aggregation**, number of Keep Alive attempts, Keep Alive interval, retry interval, vLAG Health Check peer IP address.
`vlagArg4` | This is an overloaded BGP variable. Please refer to the [cnos_vlag module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_template.html?cp=0_3_1_0_2_10) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: LAG Number, **default**, **management**.
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_vlag.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_vlag_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_vlag_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_vlag_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do VLAG configurations
hosts: cnos_vlag_sample
gather_facts: no
connection: local
roles:
- cnos_vlag_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_vlag_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_vlag_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,51 @@
# This contain sample template execution tasks
---
- name: Test Vlag - enable
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}'
with_items: "{{test_vlag_data1}}"
- name: Test Vlag - autorecovery
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data2}}"
- name: Test Vlag - config-consistency
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data3}}"
- name: Test Vlag - isl
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data4}}"
- name: Test Vlag - mac-address-table
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}'
with_items: "{{test_vlag_data5}}"
- name: Test Vlag - peer-gateway
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}'
with_items: "{{test_vlag_data6}}"
- name: Test Vlag - priority
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data7}}"
- name: Test Vlag - startup-delay
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data8}}"
- name: Test Vlag - tier-id
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data9}}"
- name: Test Vlag - vrrp
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}'
with_items: "{{test_vlag_data10}}"
- name: Test Vlag - instance
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}' vlagArg3='{{item.vlagArg3}}'
with_items: "{{test_vlag_data11}}"
- name: Test Vlag - instance2
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}'
with_items: "{{test_vlag_data12}}"
- name: Test Vlag - keepalive-attempts
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}' vlagArg3='{{item.vlagArg3}}'
with_items: "{{test_vlag_data13}}"
- name: Test Vlag - keepalive-interval
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}' vlagArg3='{{item.vlagArg3}}'
with_items: "{{test_vlag_data14}}"
- name: Test Vlag - retry-interval
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}' vlagArg3='{{item.vlagArg3}}'
with_items: "{{test_vlag_data15}}"
- name: Test Vlag - peer ip
cnos_vlag: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlag_{{ inventory_hostname }}_output.txt vlagArg1='{{item.vlagArg1}}' vlagArg2='{{item.vlagArg2}}' vlagArg3='{{item.vlagArg3}}'
with_items: "{{test_vlag_data16}}"
# Completed file

View file

@ -0,0 +1,33 @@
---
test_vlag_data1:
- {vlagArg1: "enable"}
test_vlag_data2:
- {vlagArg1: "auto-recovery", vlagArg2: 266}
test_vlag_data3:
- {vlagArg1: "config-consistency", vlagArg2: "strict"}
test_vlag_data4:
- {vlagArg1: "isl", vlagArg2: 33}
test_vlag_data5:
- {vlagArg1: "mac-address-table"}
test_vlag_data6:
- {vlagArg1: "peer-gateway"}
test_vlag_data7:
- {vlagArg1: "priority", vlagArg2: 1313}
test_vlag_data8:
- {vlagArg1: "startup-delay", vlagArg2: 323}
test_vlag_data9:
- {vlagArg1: "tier-id", vlagArg2: 313}
test_vlag_data10:
- {vlagArg1: "vrrp"}
test_vlag_data11:
- {vlagArg1: "instance", vlagArg2: 33, vlagArg3: 333}
test_vlag_data12:
- {vlagArg1: "instance", vlagArg2: "33"}
test_vlag_data13:
- {vlagArg1: "hlthchk", vlagArg2: "keepalive-attempts", vlagArg3: 13}
test_vlag_data14:
- {vlagArg1: "hlthchk", vlagArg2: "keepalive-interval", vlagArg3: 131}
test_vlag_data15:
- {vlagArg1: "hlthchk", vlagArg2: "retry-interval", vlagArg3: 133}
test_vlag_data16:
- {vlagArg1: "hlthchk", vlagArg2: "peer-ip", vlagArg3: "1.2.3.4"}

View file

@ -0,0 +1,114 @@
# Ansible Role: cnos_vlan_sample - Switch VLAN configuration
---
<add role description below>
This role is an example of using the *cnos_vlan.py* Lenovo module in the context of CNOS switch configuration. This module allows you to work with VLAN related configurations. The operators used are overloaded to ensure control over switch VLAN configurations.
The first level of VLAN configuration allows to set up the VLAN range, the VLAN tag persistence, a VLAN access map and access map filter. After passing this level, there are five VLAN arguments that will perform further configurations. They are *vlanArg1*, *vlanArg2*, *vlanArg3*, *vlanArg4*, and *vlanArg5*. The value of *vlanArg1* will determine the way following arguments will be evaluated.
The results of the operation can be viewed in *results* directory.
For more details, see [Lenovo modules for Ansible: cnos_vlan](http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_vlan.html&cp=0_3_1_0_4_14).
## Requirements
---
<add role requirements information below>
- Ansible version 2.2 or later ([Ansible installation documentation](http://docs.ansible.com/ansible/intro_installation.html))
- Lenovo switches running CNOS version 10.2.1.0 or later
- an SSH connection to the Lenovo switch (SSH must be enabled on the network device)
## Role Variables
---
<add role variables information below>
Available variables are listed below, along with description.
The following are mandatory inventory variables:
Variable | Description
--- | ---
`username` | Specifies the username used to log into the switch
`password` | Specifies the password used to log into the switch
`enablePassword` | Configures the password used to enter Global Configuration command mode on the switch (this is an optional parameter)
`hostname` | Searches the hosts file at */etc/ansible/hosts* and identifies the IP address of the switch on which the role is going to be applied
`deviceType` | Specifies the type of device from where the configuration will be backed up (**g8272_cnos** - G8272, **g8296_cnos** - G8296)
The values of the variables used need to be modified to fit the specific scenario in which you are deploying the solution. To change the values of the variables, you need to visits the *vars* directory of each role and edit the *main.yml* file located there. The values stored in this file will be used by Ansible when the template is executed.
The syntax of *main.yml* file for variables is the following:
```
<template variable>:<value>
```
You will need to replace the `<value>` field with the value that suits your topology. The `<template variable>` fields are taken from the template and it is recommended that you leave them unchanged.
Variable | Description
--- | ---
`vlanArg1` | This is an overloaded BGP variable. Please refer to the [cnos_vlan module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_vlan.html?cp=0_3_1_0_2_16) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **access-map**, **dot1q**, **filter**, specify VLAN.
`vlanArg2` | This is an overloaded BGP variable. Please refer to the [cnos_vlan module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_vlan.html?cp=0_3_1_0_2_16) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: VLAN access map name, **egress-only**, **name**, **flood**, **state**, **ip**.
`vlanArg3` | This is an overloaded BGP variable. Please refer to the [cnos_vlan module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_vlan.html?cp=0_3_1_0_2_16) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **action**, **match**, **statistics**, specify VLAN, name of the VLAN, **ipv4**, **ipv6**, **active**, **suspend**, **fast-leave**, **last-member-query-interval**, **mrouter**, **querier**, **querier-timeout**, **query-interval**, **query-max-response-time**, **report-suppression**, **robustness-variable**, **startup-query-count**, **startup-query-interval**.
`vlanArg4` | This is an overloaded BGP variable. Please refer to the [cnos_vlan module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_vlan.html?cp=0_3_1_0_2_16) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: **drop**, **forward**, **redirect**, **ip**, **mac**, last member query interval, **ethernet**, **port-aggregation**, querier IP address, querier timeout interval, query interval, query maximum response interval, robustness variable value, numbers of queries sent at startup, startup query interval.
`vlanArg5` | This is an overloaded BGP variable. Please refer to the [cnos_vlan module documentation](http://ralfss28.labs.lenovo.com:5555/help/topic/com.lenovo.switchmgt.ansible.doc/cnos_vlan.html?cp=0_3_1_0_2_16) for detailed information on usage. The values of these variables depend on the configuration context and the choices are the following: ACL name, specify ethernet port, LAG number.
## Dependencies
---
<add dependencies information below>
- username.iptables - Configures the firewall and blocks all ports except those needed for web server and SSH access.
- username.common - Performs common server configuration.
- cnos_vlan.py - This modules needs to be present in the *library* directory of the role.
- cnos.py - This module needs to be present in the PYTHONPATH environment variable set in the Ansible system.
- /etc/ansible/hosts - You must edit the */etc/ansible/hosts* file with the device information of the switches designated as leaf switches. You may refer to *cnos_vlan_sample_hosts* for a sample configuration.
Ansible keeps track of all network elements that it manages through a hosts file. Before the execution of a playbook, the hosts file must be set up.
Open the */etc/ansible/hosts* file with root privileges. Most of the file is commented out by using **#**. You can also comment out the entries you will be adding by using **#**. You need to copy the content of the hosts file for the role into the */etc/ansible/hosts* file. The sample hosts file for the role is located in the main directory.
```
[cnos_vlan_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos
10.241.107.40 username=<username> password=<password> deviceType=g8272_cnos
```
**Note:** You need to change the IP addresses to fit your specific topology. You also need to change the `<username>` and `<password>` to the appropriate values used to log into the specific Lenovo network devices.
## Example Playbook
---
<add playbook samples below>
To execute an Ansible playbook, use the following command:
```
ansible-playbook cnos_vlan_sample.yml -vvv
```
`-vvv` is an optional verbos command that helps identify what is happening during playbook execution. The playbook for each role is located in the main directory of the solution.
```
- name: Module to do VLAN configurations
hosts: cnos_vlan_sample
gather_facts: no
connection: local
roles:
- cnos_vlan_sample
```
## License
---
<add license information below>
Copyright (C) 2017 Lenovo, Inc.
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ansible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Ansible. If not, see <http://www.gnu.org/licenses/>.

View file

@ -0,0 +1,15 @@
# You have to paste this dummy information in /etc/ansible/hosts
# Notes:
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
#
# In the /etc/ansible/hosts file u have to enter [cnos_vlan_sample] tag
# Following you should specify IP Addresses details
# Please change <username> and <password> with appropriate value for your switch.
[cnos_vlan_sample]
10.241.107.39 username=<username> password=<password> deviceType=g8272_cnos

View file

@ -0,0 +1,38 @@
# This contain sample template execution task
---
- name: Test Vlan - Create a vlan, name it
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}'
with_items: "{{cnos_vlan_data1}}"
- name: Test Vlan - Create a vlan, Flood configuration
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}'
with_items: "{{cnos_vlan_data2}}"
- name: Test Vlan - Create a vlan, State configuration
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}'
with_items: "{{cnos_vlan_data3}}"
- name: Test Vlan - VLAN Access map1
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}'
with_items: "{{cnos_vlan_data4}}"
- name: Test Vlan - VLAN Accep Map2
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}'
with_items: "{{cnos_vlan_data5}}"
- name: Test Vlan - ip igmp snooping query interval
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}'
with_items: "{{cnos_vlan_data6}}"
- name: Test Vlan - ip igmp snooping last member query interval
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}'
with_items: "{{cnos_vlan_data7}}"
- name: Test Vlan - ip igmp snooping mrouter interface port-aggregation
cnos_vlan: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} outputfile=./results/cnos_vlan_{{ inventory_hostname }}_output.txt vlanArg1='{{item.vlanArg1}}' vlanArg2='{{item.vlanArg2}}' vlanArg3='{{item.vlanArg3}}' vlanArg4='{{item.vlanArg4}}' vlanArg5='{{item.vlanArg5}}'
with_items: "{{cnos_vlan_data8}}"
- name: Idempotent Command
cnos_command: host={{ inventory_hostname }} username={{ hostvars[inventory_hostname]['username']}} password={{ hostvars[inventory_hostname]['password']}} deviceType={{ hostvars[inventory_hostname]['deviceType']}} clicommand='{{item.clicommand}}' outputfile=./results/cnos_command_{{ inventory_hostname }}_output.txt
with_items: "{{cnos_vlan_data9}}"
# Completed file

View file

@ -0,0 +1,19 @@
---
cnos_vlan_data1:
- {vlanArg1: 13, vlanArg2: "name", vlanArg3: "anil"}
cnos_vlan_data2:
- {vlanArg1: 13, vlanArg2: "flood", vlanArg3: "ipv4"}
cnos_vlan_data3:
- {vlanArg1: 13, vlanArg2: "state", vlanArg3: "active"}
cnos_vlan_data4:
- {vlanArg1: "access-map", vlanArg2: "anil", vlanArg3: "statistics"}
cnos_vlan_data5:
- {vlanArg1: "access-map", vlanArg2: "anil", vlanArg3: "action", vlanArg4: "forward"}
cnos_vlan_data6:
- {vlanArg1: 13, vlanArg2: "ip", vlanArg3: "query-interval", vlanArg4: 1313}
cnos_vlan_data7:
- {vlanArg1: 13, vlanArg2: "ip", vlanArg3: "last-member-query-interval", vlanArg4: 23}
cnos_vlan_data8:
- {vlanArg1: 13, vlanArg2: "ip", vlanArg3: "mrouter", vlanArg4: "port-aggregation", vlanArg5: 23}
cnos_vlan_data9:
- {clicommand: "no vlan 13"}

View file

@ -0,0 +1,2 @@
---
# defaults for ec2_elb_setup

View file

@ -0,0 +1,6 @@
<html>
<head>Hi!</head>
<body>
Hello!
</body>
</html>

View file

@ -0,0 +1 @@
dependencies: []

View file

@ -0,0 +1,19 @@
---
# tasks file for ec2_elb_setup
# ============================================================
# install apache on the ec2 instances
- name: install apache on new ec2 instances
package: name=httpd
when: ansible_os_family == 'RedHat'
- name: install apache on new ec2 instances
package: name=apache
when: ansible_os_family == 'Debian'
- name: start and enable apache
service: name=httpd state=started enabled=yes
- name: create an index.html landing page
copy: dest=/var/www/html/index.html src=index.html owner=root group=root mode=0644

View file

@ -0,0 +1,3 @@
---
# defaults file for ec2_provision_isntances
count: 1

View file

@ -0,0 +1,4 @@
dependencies:
- prepare_tests
- setup_sshkey
- setup_ec2

View file

@ -0,0 +1,49 @@
---
# tasks file for ec2_provision_instances
# ============================================================
# create a keypair using the ssh key
- name: create the keypair for ec2
ec2_key:
name: "{{ resource_prefix }}"
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
key_material: "{{ key_material }}"
wait: yes
state: present
# ============================================================
# create some instances for testing, and add them to a new
# group ("ec2") for use later
- name: create ec2 instances for testing
ec2:
instance_type: t1.micro
image: ami-fb8e9292
group: default
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
key_name: "{{ resource_prefix }}"
wait: yes
instance_tags:
Name: "{{ resource_prefix }}"
exact_count: "{{ count }}"
count_tag:
Name: "{{ resource_prefix }}"
register: ec2_provision_result
- name: add ec2 instances to a new group
add_host:
hostname: "{{ item.public_ip }}"
groups: "ec2"
ansible_ssh_private_key_file: "{{ sshkey }}"
with_items: ec2_provision_result.instances
- name: wait for the instances to become available
wait_for:
port: 22
host: "{{ item.public_ip }}"
with_items: ec2_provision_result.instances

View file

@ -0,0 +1,6 @@
---
testcase: "*"
test_cases: []
nitro_user: nsroot
nitro_pass: nsroot

View file

@ -0,0 +1,5 @@
[netscaler]
netscaler01 nsip=172.18.0.2 nitro_user=nsroot nitro_pass=nsroot

View file

@ -0,0 +1,6 @@
---
- { include: testbed.yaml, state: present }
- { include: nitro.yaml, tags: ['nitro'] }
- { include: testbed.yaml, state: absent }

View file

@ -0,0 +1,14 @@
- name: collect all nitro test cases
find:
paths: "{{ role_path }}/tests/nitro"
patterns: "{{ testcase }}.yaml"
register: test_cases
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -0,0 +1,16 @@
---
- name: Setup lb vserver
delegate_to: localhost
netscaler_lb_vserver:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: "{{ state }}"
name: lb-vserver-1
ipv46: 10.79.1.4
port: 80
servicetype: ANY

View file

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/target_expression/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_expression/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

View file

@ -0,0 +1,13 @@
---
- name: Setup cs action
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_action:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: action-2

View file

@ -0,0 +1,14 @@
---
- name: Setup cs action
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_action:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
name: action-2
targetvserverexpr: '"mylb_" + HTTP.REQ.URL.SUFFIX'

View file

@ -0,0 +1,85 @@
---
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/update.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/update.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/update.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/update.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/target_lb_vserver/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

View file

@ -0,0 +1,13 @@
---
- name: Setup cs action
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_action:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: action-1

View file

@ -0,0 +1,15 @@
---
- name: Setup cs action
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_action:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
name: action-1
targetlbvserver: lb-vserver-1
comment: some comment

View file

@ -0,0 +1,14 @@
---
- name: Update cs action
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_action:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
name: action-1
targetlbvserver: lb-vserver-1
comment: some other comment

View file

@ -0,0 +1,6 @@
---
testcase: "*"
test_cases: []
nitro_user: nsroot
nitro_pass: nsroot

View file

@ -0,0 +1,5 @@
[netscaler]
netscaler01 nsip=172.18.0.2 nitro_user=nsroot nitro_pass=nsroot

View file

@ -0,0 +1,6 @@
---
- { include: testbed.yaml, state: present }
- { include: nitro.yaml, tags: ['nitro'] }
- { include: testbed.yaml, state: absent }

View file

@ -0,0 +1,14 @@
- name: collect all nitro test cases
find:
paths: "{{ role_path }}/tests/nitro"
patterns: "{{ testcase }}.yaml"
register: test_cases
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -0,0 +1,15 @@
---
- name: Setup cs action
delegate_to: localhost
netscaler_cs_action:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: "{{ state }}"
name: action-1
targetvserverexpr: '"mylb_" + HTTP.REQ.URL.SUFFIX'

View file

@ -0,0 +1,85 @@
---
- include: "{{ role_path }}/tests/nitro/policy_domain/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/update.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/update.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/update.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/update.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_domain/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

View file

@ -0,0 +1,13 @@
---
- name: Setup cs policy
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_policy:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
policyname: somepolicy

View file

@ -0,0 +1,14 @@
---
- name: Setup cs policy
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_policy:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
policyname: somepolicy
domain: example.com

View file

@ -0,0 +1,13 @@
---
- name: Update cs policy
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_cs_policy:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
policyname: somepolicy
domain: example2.com

View file

@ -0,0 +1,57 @@
---
- include: "{{ role_path }}/tests/nitro/policy_rule/setup.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/setup.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/setup.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/setup.yaml"
vars:
check_mode: no
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/remove.yaml"
vars:
check_mode: yes
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/remove.yaml"
vars:
check_mode: no
- assert:
that: result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/remove.yaml"
vars:
check_mode: yes
- assert:
that: not result|changed
- include: "{{ role_path }}/tests/nitro/policy_rule/remove.yaml"
vars:
check_mode: no
- assert:
that: not result|changed

Some files were not shown because too many files have changed in this diff Show more