Exercise 7: Creating a Survey

Read this in other languages: uk English, japan 日本語, Español Español.

Table of Contents

Objective

Demonstrate the use of Automation controller survey feature. Surveys set extra variables for the playbook similar to ‘Prompt for Extra Variables’ does, but in a user-friendly question and answer way. Surveys also allow for validation of user input.

Guide

Step 1: Create a Job Template

  1. Open the web UI and click on the Templates link on the left menu.

    templates link

  2. Click on the blue Add button and select Add job template to create a new job template (make sure to select Job Template and not Workflow Template)

    Parameter Value
    Name Network-Banner
    Job Type Run
    Inventory Workshop Inventory
    Project Workshop Project
    Execution Environment Default execution environment
    Playbook playbooks/network_banner.yml
    Credential Workshop Credential
  3. Scroll down and click the blue Save button.

Step 2: Examine the playbook

Here is what the network_banner.yml Ansible Playbook looks like:

---
- name: set router banners
  hosts: routers
  gather_facts: no

  tasks:
    - name: load banner onto network device
      vars:
        - network_banner:  "{{ net_banner | default(None) }}"
        - banner_type: "{{ net_type | default('login') }}"
      include_role:
        name: "../roles/banner"

Note:

You can also view the Ansible Playbook here: https://github.com/network-automation/toolkit

The role banner has a very simple main.yml file:

- name: configure banner
  include_tasks: "{{ ansible_network_os }}.yml"

The ansible_network_os variable is being used to parameterize the network OS and create a vendor neutral playbook.

If you are working with a junos device, this playbook would call for a task file called junos.yml. If you are using an IOS-XE device, this playbook would call for a task file called ios.yml. This file will in turn contain the platform specific tasks:

---
- name: add the junos banner
  junos_banner:
    text: "{{ network_banner }}"
    banner: "{{ banner_type }}"

Note:

Please observe that there are task files created for ios, nxos, eos and junos for this playbook.

Also note that we are passing in 2 variables to the task file.

  1. network_banner: This variable is populated using the net_banner variable

  2. banner_type: This variable is populated by a variable named net_type

Step 3: Create a survey

In this step you will create a “survey” of user input form to collect input from the user and populate the values for the variables net_banner and banner_type

  1. Click on the Survey tab within the Network-Banner Job Template

    add survey button

  2. Click the blue Add button

    add survey button

  3. Fill out the fields

    Parameter Value
    Question Please enter the banner text
    Description Please type into the text field the desired banner
    Answer Variable Name net_banner
    Answer type Textarea
    Required Checkmark

    For example:

    workshop survey

  4. Click Save

  5. Click the blue Add button back in the Survey tab to create another question

    add survey button

  6. Next we will create a survey prompt to gather the banner_type. This will either be “motd” or “login” and will default to “login” per the playbook above.

    Parameter Value
    Question Please enter the banner type
    Description Please choose an option
    Answer Variable Name net_type
    Answer type Multiple Choice(single select)
    Multiple Choice Options login
    motd
    default answer login
    Required Checkmark

    For example:

    workshop survey

  7. Click Save

  8. Ensure the toggle switch is set to Survey Enabled

    workshop survey toggle

  9. Click Back to Templates

Step 4: Launch the Job Template

  1. Click on the rocket ship to launch the job template.

    rocket launch

    The job will immediately prompt the user to set the banner and the type.

  2. Type in the banner message you want for the routers.

  3. Choose between login and motd.

  4. Click next to see how the survey rendered the input as extra vars for the Ansible Playbook. For this example the banner text is set as “This router was configured by Ansible”.

    survey screen

  5. Click the blue Launch button to kick off the job.

    launch button

Let the job run to completion. Let the instructor know if anything fails.

Step 5: Verify the banner

  1. Login to one of the routers and see the banner setup

    [student1@ansible]$ ssh rtr1
    

    The banner will appear on login. Here is an example from above:

    [student1@ansible-1 ~]$ ssh rtr1
    Warning: Permanently added 'rtr1,3.237.253.154' (RSA) to the list of known hosts.
    
    This router was configured by Ansible
    
  2. Verify on additional routers

Takeaways

You have successfully demonstrated

Complete

You have completed lab exercise 7


Previous Exercise | Next Exercise

Click here to return to the Ansible Network Automation Workshop