Read this in other languages:
English, 日本語, Portuguese do Brasil, Française, Español
Demonstrate the use of the Ansible Automation Controller survey feature. Surveys allow for setting extra variables for the playbook, similar to ‘Prompt for Extra Variables,’ but in a user-friendly Q&A format. They also allow for validation of user input.
You’ve installed Apache on all hosts in the job you just ran. Now, let’s build on this:
index.html
file.index.html
template.Additionally, the role will ensure that the Apache configuration is set up correctly for this exercise.
Tip
The survey feature provides a simple query for data but does not support dynamic data queries, nested menus, or four-eye principles.
The playbook and role with the Jinja2 template are located in the GitHub repository https://github.com/ansible/workshop-examples in the rhel/apache
directory.
apache_role_install.yml
, which references the role.roles/role_apache
subdirectory.templates/index.html.j2
template file marked by ``.tasks/main.yml
file deploys the template.The playbook creates a file (dest) on the managed hosts from the template (src).
Because the playbook and role are located in the same GitHub repo as the apache_install.yml
playbook, you don’t need to configure a new project for this exercise.
Now, let’s create a new Template that includes a survey.
Go to Automation Execution → Templates, click the Create template button, and choose Create job template.
Fill out the following details:
Parameter | Value |
---|---|
Name | Create index.html |
Job Type | Run |
Inventory | Workshop Inventory |
Project | Workshop Project |
Playbook | rhel/apache/apache_role_install.yml |
Execution Environment | Default execution environment |
Credentials | Workshop Credential |
Limit | web |
Options | Privilege Escalation |
Warning
Do not run the template yet!
Parameter | Value |
---|---|
Question | First Line |
Answer Variable Name | first_line |
Answer Type | Text |
Parameter | Value |
---|---|
Question | Second Line |
Answer Variable Name | second_line |
Answer Type | Text |
Now, launch the Create index.html job template by clicking the Launch template button.
Before the job starts, the survey will prompt for First Line and Second Line. Enter your text and click Next. The Preview window shows the values—if all looks good, click Finish to start the job.
Once the job completes, verify the Apache homepage by running the following curl
command in the SSH console on the control host:
Go to Automation Execution → Infrastructure → Inventories → Workshop Inventory
In the **Automation Execution → Infrastructure → Inventories → Workshop Inventory, select the Hosts tab and select node1 and click Run Command
Within the Details window, select Module command, in Arguments type curl http://node1
and click Next.
Within the Execution Environment window, select Default execution environment and click Next.
Within the Credential window, select Workshop Credentials and click Next.
Review your inputs and click Finish.
Verify that the output result is as expected.
Navigation