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 selectJob Template
and notWorkflow 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 -
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 thenet_banner
variable -
banner_type
: This variable is populated by a variable namednet_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
motddefault 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
andmotd
. -
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
[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
* Creation of a Job Template for configuring a banner on multiple network operating systems including Arista EOS, Cisco IOS and Juniper Junos.
* Creation of a self service survey for the Job Template to fill out the `network_banner` and `banner_type` variables
* Executing a Job Template on all four routers, loading a banner on them simultaneously
## Complete
You have completed lab exercise 7
---
[Previous Exercise](../6--controller-job-template/README.md) | [Next Exercise](../8-controller-rbac/README.md)
[Click here to return to the Ansible Network Automation Workshop](../README.md)