Appendix G: picos_config Ansible Module Overview and Example Playbooks


Ansible is an IT automation framework that is used for infrastructure configuration management.

picos_config Ansible module manages configurations on devices running PICOS. picos_config Ansible module software is included in AmpCon Server software version 1.4 and later.

picos_config Module Benefits

picos_config Ansible module software has the following benefits:

  • Only configure the set commands that are not present in the switch or the ones that need to be changed.
  • Ability to compare the difference between input configuration file and actual configuration present in the switch.
  • Show configurations and other switch information.

picos_config Module Usage Examples

Here are several usage examples for picos_config module when using Ansible to run single task/module:

    • Set Configuration Commands Example
      ansible leaf_switches -m picos_config -a "mode='cli_config' cmd='set interface gigabit-ethernet ge-1/1/1 mtu 1500’”
    • Show Configuration Commands Example
      ansible leaf_switches -m picos_config -a "mode='cli_show' cmd='show running-config interface gigabit-ethernet ge-1/1/1 | display set'"
      ansible leaf_switches -m picos_config -a "mode='cli_show' cmd='show running-config | display set’”
    • Example for Executing a Command in Linux
      • License information
        ansible leaf_switches -m picos_config -a "mode='shell' cmd='license -s'"
      • Hard drive utilization
        ansible leaf_switches -m picos_config -a "mode='shell' cmd='df -h'"
      • System uptime
        ansible leaf_switches -m picos_config -a "mode='shell' cmd='uptime’”
    • Example for Setting Configuration Commands From an Input File
      ansible leaf_switches -m picos_config -a "mode='config_load' cmd='/home/admin/setconf1.config'"

picos_config Ansible Module Example Playbooks 

A collection of simple Ansible Playbooks to configure and verify PICOS  can be download here PICOSExamplePlaybooks.zip.

Playbooks provided are in YAML format. Unzip the downloaded file. Playbooks files are in  .yml extension. Choose the Playbook file you want to execute in AmpCon. There are three types of Playbooks:

(1) Simple playbook that does not need  input value for variables defined in it or playbooks that does not use a configuration text file.

(2) Simple Playbook that need input value for variables.

(3) Playbooks that use configuration text file.

Executing Simple Playbook With or Without Variables

Let us take the show_switch_port.yml playbook example. It prints switch host name and port number to which a specific MAC address endpoint is connected. Following is the playbook code:

- name:  Get a switch port for a given Mac Address
  hosts: all
  tasks:
  - name: Get switch port for a given Mac Address
    picos_config: mode='cli_show' cmd='show mac-address table | match {{MacAddr}} '
    register: exec_result
  - name: Show execution result
    debug: var=exec_result.stdout_lines

Please noteMacAddr is a variable defined in this playbook. Variable is included in a set of curly braces as shown above.

Executing a simple playbook in AmpCon consists of the following steps.

1. Select the Automation>Playbooks menu, and click +Playbooks as shown below:

2. Enter name of the playbook and description as shown below and click Please note: Name of the playbook field need to be less than 20 characters and no spaces. Description field need to be less than 40 characters.

 

3. Make sure playbook.yml is highlighted. Cut and paste the following example playbook show_switch_port.yml provided in the window as shown below. Click Save All.

 

4. Click Run as shown below.

 5. Select the switch or group of switches for running the playbook as shown below and click Next.

6. Enter name of the variable and its value in JSON format shown below and click Next. Otherwise if your Playbook does not have any variable, then simply click Next.

 

7. Click Run Playbook as shown below.

 


8. To check playbook execution result, select the Automation > Job list menu, and click Task Results as shown below for the playbook you just executed.

 Click Show Result as shown below to see the output of playbook execution:

Executing Playbooks That Use Configuration Text File

Let us take the conf_snmpv3.yml playbook example. It copies the snmpv3.conf file containing SNMPv3 configuration to the switch,  and then loads the configuration. Following is the playbook code:

---
- name: Configure SNMP v3 in switches
  hosts: all
  tasks:
  - name: Transfer the script
    copy: src=snmpv3.conf dest=/home/admin/snmpv3.conf force=yes mode=0777
 
  - name: Activate the configuration
    picos_config: mode='config_load' cmd='/home/admin/snmpv3.conf'
    register: exec_result 

  - name: Show execution result
    debug: var=exec_result.stdout_lines

Executing  a playbook that loads and executes a  configuration file on the switch consists of the following steps:

1. Rename yml as playbook.yml.

2. Create a zip file snmpv3.zip that includes playbook.yml and snmpv3.conf.

3. Select the Automation>Playbooks menu, and click Import as shown below:


Enter the Playbook Name and Description as shown below. Upload the Zip File and click Import.

 

4. Click Run as shown below.

 

 Select the switch or group of switches for running the playbook as shown below and click Next two times.

 

Click Run Playbook as shown below.

 

5. To check playbook execution result, select the Automation>Job list menu, and click Task Results as shown below for the playbook you just executed. 

 Click Show Result as shown below.

 

SNMPv3 configured commands are shown below.

 

 

 

 

 





Copyright © 2024 Pica8 Inc. All Rights Reserved.