Read this in other languages: English, 日本語, Español.
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.
Open the web UI and click on the Templates
link on the left menu.
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 | network workshop execution environment |
Playbook | playbooks/network_banner.yml |
Credential | Workshop Credential |
Scroll down and click the blue Save
button.
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.
network_banner
: This variable is populated using the net_banner
variable
banner_type
: This variable is populated by a variable named net_type
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
Click on the Survey tab within the Network-Banner Job Template
Click the blue Add button
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:
Click Save
Click the blue Add
button back in the Survey tab to create another question
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:
Click Save
Ensure the toggle switch is set to Survey Enabled
Click Back to Templates
Click on the rocket ship to launch the job template.
The job will immediately prompt the user to set the banner and the type.
Type in the banner message you want for the routers.
Choose between login
and motd
.
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”.
Click the blue Launch button to kick off the job.
Let the job run to completion. Let the instructor know if anything fails.
Login to one of the routers and see the banner setup
[student@ansible]$ ssh rtr1
The banner will appear on login. Here is an example from above:
[student@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
Verify on additional routers
You have successfully demonstrated
network_banner
and banner_type
variablesYou have completed lab exercise 7
Previous Exercise | Next Exercise
Click here to return to the Ansible Network Automation Workshop