Skip to content

Ansible Tower Integration

tchiapuziowong edited this page May 20, 2019 · 2 revisions

Prerequisites

Ansible Tower Setup - Example Project

The following describes how to set up an example project and inventory for our Modules in Ansible Tower. This is not the same setup as used within the actual project. The documentation for the actual project can be found below.

Aruba Switch Credential

The first step is to create custom credential which stores the ArubaOS-Switch's Username and Password (encrypted) for the usage of our Playbooks.

Create Custom Credentials - Single Usage

The following describes how to create custom credentials for the usage of only one module type (ArubaOS-Switch or ArubaOS-CX) within one Playbook.

  1. Please navigate in the Ansible Tower WebUI to Options (Gear in right corner).
  2. On the Options Page please select "Credential Types".
  3. Click the "+ADD" Button on the new Credential Types Page.
  4. Fill out the:
    1. Choose a Name your think that fits (e.g. Aruba-Custom-Credential)
    2. Fill the following into "Input Configuration" field below the first line ("---"). This will create a custom credential template in which you can later enter username and password.
     fields:
       - type: string
         id: username
         label: Username
       - type: string
         id: password
         label: Password
         secret: true
     required:
       - username
       - password
     
    1. Fill the following into "Injector Configuration" field below the first line ("---"). This will create variables which are going to be used by Ansible (Inventory and Playbooks). We are using these variables ("ansible_user", "ansible_password") for the connection automatically and they do not need to be used within the Playbook to connect.
     extra_vars:
       ansible_password: '{{ password }}'
       ansible_user: '{{ username }}'
     
    1. Click Save

Add ArubaOS-Switch Host into Inventory

The connection Plugin will need three more variable inside the host variable of the switch in the inventory to automatically connect. This will cover an example of just these variables. You could also add further variables into this Inventory if needed.

This is an example of how to create a test inventory:

  • Prerequisite: Have an existing Inventory created.
  1. Move to the inventory and edit it
  2. Move to Hosts
  3. Add a new Host
  4. Give the Host a Name (e.g. switch1_aoss)
  5. Fill "Variables" below "---" with the following. Replace "TARGET_IP" with the IP of the Switch:
     ansible_host: TARGET_IP
     ansible_connection: local 
     ansible_network_os: arubaoss   
    
  6. Click Save

Next up is creating custom credentials for ArubaOS-Switch devices:

  1. Move to Options
  2. Move to Credentials
  3. Click "+ADD"
  4. Choose a name (e.g.: "ArubaOS-Switch Credentials")
  5. Select Credential Type and choose the name you have chosen above for the Aruba Custom Credentials (in our case "Aruba-Custom-Credential-Switch")
  6. Enter Username and Password
  7. Click Save

You can now create a job template with the Inventory and the Custom Credentials for our Modules.

Add ArubaOS-CX Host into Inventory

The connection Plugin will need three more variable inside the host variable of the switch in the inventory to automatically connect. This will cover an example of just these variables. You could also add further variables into this Inventory if needed.

This is an example of how to create a test inventory:

  • Prerequisite: Have an existing Inventory created.
  1. Move to the inventory and edit it
  2. Move to Hosts
  3. Add a new Host
  4. Give the Host a Name (e.g. switch1_cx)
  5. Fill "Variables" below "---" with the following. Replace "TARGET_IP" with the IP of the CX:
     ansible_host: TARGET_IP
     ansible_connection: arubaoscx_rest
    
  6. Click Save

Next up is creating custom credentials for ArubaOS-CX devices:

  1. Move to Options
  2. Move to Credentials
  3. Click "+ADD"
  4. Choose a name (e.g.: "ArubaOS-CX Credentials")
  5. Select Credential Type and choose the name you have chosen above for the Aruba Custom Credentials (in our case "Aruba-Custom-Credential-CX")
  6. Enter Username and Password
  7. Click Save

You can now create a job template with the Inventory and the Custom Credentials for our Modules.

Create Custom Credentials - Double Usage

The following describes how to create custom credentials for the usage of both module types within one Playbook.

  1. Please navigate in the Ansible Tower WebUI to Options (Gear in right corner).
  2. On the Options Page please select "Credential Types".
  3. Click the "+ADD" Button on the new Credential Types Page.
  4. Fill out the:
    1. Choose a Name your think that fits (e.g. Aruba-Custom-Credential Double)
    2. Fill the following into "Input Configuration" field below the first line ("---"). This will create a custom credential template in which you can later enter username and password.
     fields:
       - type: string
         id: username
         label: Username Switch
       - secret: true
         type: string
         id: password
         label: Password Switch
       - type: string
         id: username_cx
         label: Username CX
       - secret: true
         type: string
         id: password_cx
         label: Password CX
     required:
       - username
       - password
       - username_cx
       - password_cx
     
    1. Fill the following into "Injector Configuration" field below the first line ("---"). This will create variables which are going to be used by Ansible (Inventory and Playbooks). We are using these variables ("ansible_user", "ansible_password") for the connection automatically and they do not need to be used within the Playbook to connect. "password" and "user" will be parsed to the connection plugin within the playbook to not create variables with the same name.
     extra_vars:
       ansible_password: '{{ password_cx }}'
       ansible_user: '{{ username_cx }}'
       password: '{{ password }}'
       user: '{{ username }}'
     
  5. Create a credential similar to the process above but with this credential type and use it the for the Playbook.

Module Usage - Example Project

If you want to use the example playbooks in the "aruba-ansible-modules/example_playbooks" directory, please follow the following instruction to set them up in Ansible Tower. These workflows expect to have everything in place from above.

Setup Module Examples for Ansible Tower

  1. First, make sure to change the hosts line in all the example playbooks from - hosts: switch1 to - hosts: all . This allows for the playbooks to be ran with any Switch or CX host.
  2. Then copy all Playbook examples into a directory in the "/var/lib/awx/projects" directory. You will need root permissions most of the time. sudo mkdir /var/lib/awx/projects/aruba_examples sudo cp aruba-ansible-modules/example_playbooks/arubaoss/* /var/lib/awx/projects/aruba_examples sudo cp aruba-ansible-modules/example_playbooks/arubaoscx/* /var/lib/awx/projects/aruba_examples
  3. Go to the WebUI of Ansible Tower and click on "Projects"
  4. Click "+ADD" and enter a Name
  5. Select "Manual" as "SCM TYPE"
  6. Choose the playbook directory you have created in "/var/lib/awx/projects", in the example we created the directory aruba_examples
  7. Click Save

ArubaOS-Switch

This explains how to add the vlan.yml example playbook for ArubaOS-Switch into Tower.

  1. Go to Ansible Tower WebUI "Templates"
  2. Press "+ADD" -> "Job Template" and enter a name
  3. Select Inventory that is filled with the information above
  4. Select Project with the name from above
  5. Choose playbook "vlan.yml"
  6. Add Credentials "SSH Decoy" for Machine Type Credential and select "Aruba-Custom-Credential Single" Type and click on the name of your credential from above. Close window by clicking select.
  7. Press save

ArubaOS-CX

This explains how to add the vlan.yml example playbook for ArubaOS-CX into Tower.

  1. Go to Ansible Tower WebUI "Templates"
  2. Press "+ADD" -> "Job Template" and enter a name
  3. Select Inventory that is filled with the information above
  4. Select Project with the name from above
  5. Choose playbook "vlan.yml"
  6. Add Credentials "SSH Decoy" for Machine Type Credential and select "Aruba-Custom-Credential Single" Type and click on the name of your credential from above. Close window by clicking select.
  7. Press save

Aruba Switching Project Integration - CentOS/Linux

Enter the following commands and follow prompts

1. $: su                                       # become root user
2. #: cd /var/lib/awx/projects                 # go to ansible tower project dir
3. _copy ansible tower project in this project_ (E.g.: sftp/winscp or something else)
4. cd into project
5. #: chmod +x ./prem.sh
6. #: ./prem.sh

Ansible Tower setup for Aruba Switching Project

The following part will cover the Ansible Tower setup for the Aruba Switching Ansible Automation project. Make sure that you already followed the Steps for Module Integration and Aruba Switching Project Integration.

Setup Project

  1. Go to the WebUI of Ansible Tower and click on "Projects"
  2. Click "+ADD" and enter a Name
  3. Select "Manual" as "SCM TYPE"
  4. Choose the playbook directory "aruba-switch-ansible-tower"
  5. Click Save

Setup Inventory

This is an example of how to create the inventory accordingly to the current project structure by hand. This will build an inventory which is capable to run all workflows. If you do not want certain variables do not enter them. Each block of specific variables is annotated by the workflow that needs them.

  1. Click on "Inventory"
  2. Click "+ADD" Inventory and enter a name
  3. Click on Save
  4. Click on Groups in the same window
  5. Click "+ADD GROUP" and enter the name "branch1"
  6. Enter the following variables below the "---" in the "Variables" Text Field in "YAML" Mode:
     # General Vars
     cx_group_name: "branch1_cxs"       # Group for the CX switches
     sw_group_name: "branch1_switches"  # Group for the ArubaOS Switches
    
     # ZTP Vars
     peer1: "cx-aa-bb-cc-dd-ee-2f" # Name of Host Variable for AOS-CX Peer 1 Switch
     peer2: "cx-aa-bb-cc-dd-ee-1f" # Name of Host Variable for AOS-CX Peer 2 Switch
    
  7. Click save
  8. Click on "Groups" in the same window
  9. Click "+ADD" and then "New Group" and enter the name "branch1_cxs"
  10. Enter the following variables below the "---" in the "Variables" Text Field in "YAML" Mode:
    group: "branch1"
    
    # Config Generator Vars
    isl_link1: "1/1/47"
    isl_link2: "1/1/48"
    isl_link_description: "link to SWAG for ISL & SVI OSPF Peering"
    upstream_link: "1/1/1"
    
  11. Click on save, click on "brnach1_cx" and then click on "Hosts" in the same window.
  12. Repeat the following steps for each AOS-CX Switch you want to add:
    1. Click "+ADD" and "New Host"
    2. Enter the mac address of the Host as name separated by "-" (e.g.: "cx-aa-bb-cc-dd-ee-1f"). If you want to use another name, make sure that you adopt the name in the branch1 group vars (Step 6) as well.
    3. Enter the following variables below the "---" in the "Variables" Text Field in "YAML" Mode:
      ip: "TARGETIP" # Replace "TARGETIP" with the IP of the Switch
      
      # Config Generator Vars
      hostname: "cx-aa-bb-cc-dd-ee-1f" # This will be the name of the file that will be created by the config generator
      
    4. Click save
  13. Scroll down and click on "branch1" in the window of your inventory (Has the name you gave to it as a header)
  14. Click on "+ ADD" and then "New Group" in the Window at the top and enter the name "branch1_switches"
  15. Enter the following variables below the "---" in the "Variables" Text Field in "YAML" Mode:
    group: "branch1"
    
    # Config Generator Vars
    uplinkvlan: 302
    uplinkvlanname: "VLAN302"
    uplinktrunk: "trk1"
    oobmip: "10.6.7.29"
    oobmmask: "255.255.255.0"
    oobmgw: "10.6.7.1"
        
    # ZTP Vars
    cx_port_subnet: "255.255.255.0"
    cx_port_vlan: 302
    
  16. Click on save, click on "brnach1_switches" and then click on "Hosts" in the same window.
  17. Repeat the following steps for each AOS-Switch Switch you want to add:
    1. Click "+ADD" and "New Host"
    2. Enter the mac address of the Host as name separated by "-" and started by "sw- (e.g.: "sw-94-18-82-dd-f3-00").
    3. Enter the following variables below the "---" in the "Variables" Text Field in "YAML" Mode:
      ip: "STATICIP" # Replace "STATICIP" with the intendet static IP of the Switch
      hostname: "branch1_2930M" # Intendet Hostname of the Switch
      sw_mac: "94:18:82:dd:f3:00" # Mac addresse seperated by ":" with "sw-" at start
      
    4. Click save

Create Custom Credentials CX

  1. Please navigate in the Ansible Tower WebUI to Options (Gear in right corner).
  2. On the Options Page please select "Credential Types".
  3. Click the "+ADD" Button on the new Credential Types Page.
  4. Fill out the:
    1. Choose a Name your think that fits (e.g. "Aruba Automation Custom Credentials-CX")
    2. Fill the following into "Input Configuration" field below the first line ("---"). This will create a custom credential template in which you can later enter username and password.
     fields:
       - type: string
         id: username
         label: Username
       - type: string
         id: password
         label: Password
         secret: true
     required:
       - username
       - password
     
    1. Fill the following into "Injector Configuration" field below the first line ("---"). This will create variables which are going to be used by Ansible (Inventory and Playbooks).
     extra_vars:
       password_cx: '{{ password }}'
       user_cx: '{{ username }}'
     

Create Custom Credentials CX

  1. Please navigate in the Ansible Tower WebUI to Options (Gear in right corner).
  2. On the Options Page please select "Credential Types".
  3. Click the "+ADD" Button on the new Credential Types Page.
  4. Fill out the:
    1. Choose a Name your think that fits (e.g. "Aruba Automation Custom Credentials-Switch")
    2. Fill the following into "Input Configuration" field below the first line ("---"). This will create a custom credential template in which you can later enter username and password.
     fields:
       - type: string
         id: username
         label: Username
       - type: string
         id: password
         label: Password
         secret: true
     required:
       - username
       - password
     
    1. Fill the following into "Injector Configuration" field below the first line ("---"). This will create variables which are going to be used by Ansible (Inventory and Playbooks).
     extra_vars:
       password: '{{ password }}'
       user: '{{ username }}'
     

Create Custom Credentials CX and Switch

  1. Please navigate in the Ansible Tower WebUI to Options (Gear in right corner).
  2. On the Options Page please select "Credential Types".
  3. Click the "+ADD" Button on the new Credential Types Page.
  4. Fill out the:
    1. Choose a Name your think that fits (e.g. "Aruba Automation Custom Credentials Switch and CX")
    2. Fill the following into "Input Configuration" field below the first line ("---"). This will create a custom credential template in which you can later enter username and password.
     fields:
       - type: string
         id: username
         label: Username Switch
       - secret: true
         type: string
         id: password
         label: Password Switch
       - type: string
         id: username_cx
         label: Username CX
       - secret: true
         type: string
         id: password_cx
         label: Password CX
     required:
       - username
       - password
       - username_cx
       - password_cx
     
    1. Fill the following into "Injector Configuration" field below the first line ("---"). This will create variables which are going to be used by Ansible (Inventory and Playbooks).
     extra_vars:
       password: '{{ password }}'
       password_cx: '{{ password_cx }}'
       user: '{{ username }}'
       user_cx: '{{ username_cx }}'
     

Fill credentials for ArubaOS-Switch and ArubaOS-CX

Next up is creating custom credentials for AOS-Switch devices:

  1. Move to Options
  2. Move to Credentials
  3. Click "+ADD"
  4. Choose a name (e.g.: "AOS-Switch Credentials", "AOS-CX Credentials" or "AOS-Switch and AOS-CX Credentials")
  5. Select Credential Type and choose the name you have chosen above for the Aruba Custom Credentials (in our case "Aruba Automation Custom Credential" ending with "Switch", "CX" or both)
  6. Enter Username and Password
  7. Click Save

You can now create a job template with the Inventory and the Custom Credentials for our Modules.

Create "Decoy" SSH Credentials for Ansible Tower

Our templates will also use credentials called "SSH_Decoy". We must use them because Ansible is forcing you to add "Machine"-Credentials in the case of creating a Workflow template. But because our automation and modules do not need SSH credentials we are supplying it with empty SSH Decoy Machine credential which will not be used.

  1. Go to Credentials
  2. Add and enter name "SSH_Decoy"
  3. Select Credential Type "Machine"
  4. Click Save (it is not needed to supply a password or username!)

Setup Job templates

The following will describe how to set up the template for each Automation Workflow. It always starts with pressing the "+ADD" Button and ends with pressing save.

AOS-CX Module Example Workflow
  1. Enter Name "AOS-CX Modules Example Workflow"
  2. Select the Inventory that you have created above
  3. Select the Project that you have created above
  4. Choose the Playbook "aoscx_module_config_example.yml"
  5. Add Credential "SSH_Decoy" from the "Machine" Credential Type and select the Custom Credential Type for AOS-CX, select the credential entry that will show and click select.
  6. Enter a Limit of Switches if you do not want to run it against all Switches. In our case, we want to only run it against one branch and thus enter "branch1_cxs" in the "Limit" field.
  7. Enter the following below "---" in the "extra variables" field:
    state: configure # configure/unconfigure to decided what Workflow shall do
    
AOS-Switch Modules Example Workflow
  1. Enter Name "AOS-Switch Modules Example Workflow"
  2. Select the Inventory that you have created above
  3. Select the Project that you have created above
  4. Choose the Playbook "aoss_module_config_example.yml"
  5. Add Credential "SSH_Decoy" from the "Machine" Credential Type and select the Custom Credential Type for AOS-Switch, select the credential entry that will show and click select.
  6. Enter a Limit of Switches if you do not want to run it against all Switches. In our case, we want to only run it against one branch and thus enter "branch1_switches" in the "Limit" field.
  7. Enter the following below "---" in the "extra variables" field:
    state: configure # configure/unconfigure to decided what Workflow shall do
    
AOS-Switch Config Workflow
  1. Enter Name "AOS-Switch Modules Example Workflow"
  2. Select the Inventory that you have created above
  3. Select the Project that you have created above
  4. Choose the Playbook "arubaos_switch_config.yml"
  5. Add Credential "SSH_Decoy" from the "Machine" Credential Type and select the Custom Credential Type for AOS-Switch, select the credential entry that will show and click select.
  6. Enter a Limit of Switches if you do not want to run it against all Switches. In our case, we want to only run it against one branch and thus enter "branch1_switches" in the "Limit" field.
AOS-Switch Firmware Workflow (SSH CLI)
  1. Enter Name "AOS-Switch Firmware Workflow (SSH CLI)"
  2. Select the Inventory that you have created above
  3. Select the Project that you have created above
  4. Choose the Playbook "arubaos_switch_firmware.yml"
  5. Add Credential "SSH_Decoy" from the "Machine" Credential Type and select the Custom Credential Type for AOS-Switch, select the credential entry that will show and click select.
  6. Enter a Limit of Switches if you do not want to run it against all Switches. In our case, we want to only run it against one branch and thus enter "branch1_switches" in the "Limit" field.
Config Generator Workflow
  1. Enter Name "Config Generator Workflow"
  2. Select the Inventory that you have created above
  3. Select the Project that you have created above
  4. Choose the Playbook "config_generator.yml"
  5. Add Credential "SSH_Decoy" from the "Machine" Credential Type and select the Custom Credential Type for AOS-Switch and AOS-CX, select the credential entry that will show and click select.
  6. Enter a Limit of Switches if you do not want to run it against all Switches. In our case, we want to only run it against one branch and thus enter "branch1" in the "Limit" field.
ZTP Solution Workflow
  1. Enter Name "ZTP Solution Workflow"
  2. Select the Inventory that you have created above
  3. Select the Project that you have created above
  4. Choose the Playbook "ztp_start.yml"
  5. Add Credential "SSH_Decoy" from the "Machine" Credential Type and select the Custom Credential Type for AOS-Switch and AOS-CX, select the credential entry that will show and click select.
  6. Enter the following below "---" in the "extra variables" field:
    site: branch1
    

Troubleshooting

Ansible Tower Job output empty?

In CLI:

ansible-tower-service restart

Ansible Tower Jobs failing before even starting to run?

If the Ansible Tower installation is consisting of multiple nodes and you set up your project manually, you might need to set up the project and modules on each node. Ansible Tower might circle through each node to run its Jobs. If it runs the Job on a node where the project does not exist, the job will fail.

  • The Error Message for this problem will occur in the Job details window of a failed Job and mention a "task.py" file.
Clone this wiki locally