Skip to content

Commit

Permalink
Merge pull request #2184 from rlopez133/aap25_rhel_workshop_ch2.4
Browse files Browse the repository at this point in the history
making changes to section 2.4 for aap 2.5
  • Loading branch information
rlopez133 authored Oct 11, 2024
2 parents db520eb + 6e38fcc commit b615375
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 183 deletions.
257 changes: 74 additions & 183 deletions exercises/ansible_rhel/2.4-surveys/README.md
Original file line number Diff line number Diff line change
@@ -1,224 +1,118 @@
# Exercise - Surveys

**Read this in other languages**:
<br>![uk](../../../images/uk.png) [English](README.md), ![japan](../../../images/japan.png)[日本語](README.ja.md), ![brazil](../../../images/brazil.png) [Portugues do Brasil](README.pt-br.md), ![france](../../../images/fr.png) [Française](README.fr.md), ![Español](../../../images/col.png) [Español](README.es.md).
<br>![UK](../../../images/uk.png) [English](README.md), ![Japan](../../../images/japan.png) [日本語](README.ja.md), ![Brazil](../../../images/brazil.png) [Portuguese do Brasil](README.pt-br.md), ![France](../../../images/fr.png) [Française](README.fr.md), ![Español](../../../images/col.png) [Español](README.es.md)

## Table Contents
## Table of Contents

* [Objective](#objective)
* [Guide](#guide)
* [The Apache-configuration Role](#the-apache-configuration-role)
* [Create the Project](#create-the-project)
* [Create a Template with a Survey](#create-a-template-with-a-survey)
* [Create Template](#create-template)
* [Add the Survey](#add-the-survey)
* [Launch the Template](#launch-the-template)
* [What About Some Practice?](#what-about-some-practice)
- [Objective](#objective)
- [Guide](#guide)
- [The Apache-Configuration Role](#the-apache-configuration-role)
- [Create the Project](#create-the-project)
- [Create a Template with a Survey](#create-a-template-with-a-survey)
- [Create Template](#create-template)
- [Add the Survey](#add-the-survey)
- [Launch the Template](#launch-the-template)
- [What About Some Practice?](#what-about-some-practice)

## Objective

Demonstrate the use of Ansible Automation controller [survey feature](https://docs.ansible.com/automation-controller/latest/html/userguide/job_templates.html#surveys). 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.
Demonstrate the use of the Ansible Automation Controller [survey feature](https://docs.ansible.com/automation-controller/latest/html/userguide/job_templates.html#surveys). 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.

## Guide

You have installed Apache on all hosts in the job you just ran. Now we’re going to extend on this:
You've installed Apache on all hosts in the job you just ran. Now, let's build on this:

* Use a proper role that has a Jinja2 template to deploy an `index.html` file.
- Use a proper role that includes a Jinja2 template to deploy an `index.html` file.
- Create a job **Template** with a survey to collect values for the `index.html` template.
- Launch the job **Template**.

* Create a job **Template** with a survey to collect the values for the `index.html` template.
Additionally, the role will ensure that the Apache configuration is set up correctly for this exercise.

* Launch the job **Template**
> **Tip**
> The survey feature provides a simple query for data but does not support dynamic data queries, nested menus, or four-eye principles.
Additionally, the role will make sure that the Apache configuration is properly set up for this exercise.
### The Apache-Configuration Role

> **Tip**
>
> The survey feature only provides a simple query for data - it does not support four-eye principles, queries based on dynamic data or nested menus.
The playbook and role with the Jinja2 template are located in the GitHub repository [https://github.com/ansible/workshop-examples](https://github.com/ansible/workshop-examples) in the `rhel/apache` directory.

### The Apache-configuration Role
- Have a look at the playbook `apache_role_install.yml`, which references the role.
- The role is located in the `roles/role_apache` subdirectory.
- Inside the role, note the two variables in the `templates/index.html.j2` template file marked by `{{…​}}`.
- The `tasks/main.yml` file deploys the template.

The playbook and the role with the Jinja2 template already exist in the Github repository [https://github.com/ansible/workshop-examples](https://github.com/ansible/workshop-examples) in the directory `rhel/apache`.
The playbook creates a file (**dest**) on the managed hosts from the template (**src**).

Head over to the Github UI and have a look at the content: the playbook `apache_role_install.yml` merely references the role. The role can be found in the `roles/role_apache` subdirectory.
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.

* Inside the role, note the two variables in the `templates/index.html.j2` template file marked by `{{…​}}`\.
* Notice the tasks in `tasks/main.yml` that deploy the file from the template.

What is this playbook doing? It creates a file (**dest**) on the managed hosts from the template (**src**).
### Create a Template with a Survey

The role deploys a static configuration for Apache. This is to make sure that all changes done in the previous chapters are overwritten and your examples work properly.
Now, let's create a new Template that includes a survey.

Because the playbook and role is located in the same Github repo as the `apache_install.yml` playbook you don't have to configure a new project for this exercise.
#### Create Template

### Create the Project
1. Go to **Automation Execution → Templates**, click the **Create template** button, and choose **Create job template**.

* Go to **Resources → Projects** click the **Add** button. Fill in the form:
2. Fill out the following details:

<table>
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
<tr>
<td>Name</td>
<td>Workshop Project</td>
</tr>
<tr>
<td>Organization</td>
<td>Default</td>
</tr>
<tr>
<td>Default Execution Environment</td>
<td>Default execution environment</td>
</tr>
<tr>
<td>Source Control Credential Type</td>
<td>Git</td>
</tr>
</table>
| Parameter | Value |
|-----------------------------|---------------------------------|
| Name | Create index.html |
| Job Type | Run |
| Inventory | Workshop Inventory |
| Project | Workshop Project |
| Execution Environment | Default execution environment |
| Playbook | `rhel/apache/apache_role_install.yml` |
| Credentials | Workshop Credential |
| Limit | web |
| Options | Privilege Escalation |

Enter the URL into the Project configuration:
3. Click **Save**.

<table>
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
<tr>
<td>Source Control URL</td>
<td><code>https://github.com/ansible/workshop-examples.git</code></td>
</tr>
<tr>
<td>Options</td>
<td>Select Clean, Delete, Update Revision on Launch to request a fresh copy of the repository and to update the repository when launching a job.</td>
</tr>
</table>
![template details](images/template_details.png)

* Click **SAVE**
> **Warning**
> **Do not run the template yet!**
#### Add the Survey

The new project will be synced automatically after creation. But you can also do this manually: Sync the Project again with the Git repository by going to the **Projects** view and clicking the circular arrow **Sync Project** icon to the right of the Project.
1. In the Template, click the **Survey** tab, then click **Create survey question**.
2. Fill out the following for the first survey question:

After starting the sync job, go to the **Jobs** view: there is a new job for the update of the Git repository.
| Parameter | Value |
|-----------------------------|-----------------|
| Question | First Line |
| Answer Variable Name | first_line |
| Answer Type | Text |

### Create a Template with a Survey
![Survey Q1](images/survey_q1.png)

Now you create a new Template that includes a survey.
3. Click **Save**.
4. Click **Create survey question** to create a second survey question:

#### Create Template
| Parameter | Value |
|-----------------------------|-----------------|
| Question | Second Line |
| Answer Variable Name | second_line |
| Answer Type | Text |

* Go to **Resources → Templates**, click the **Add** button and choose **Add job template**

* Fill out the following information:

<table>
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
<tr>
<td>Name</td>
<td>Create index.html</td>
</tr>
<tr>
<td>Job Type</td>
<td>Run</td>
</tr>
<tr>
<td>Inventory</td>
<td>Workshop Inventory</td>
</tr>
<tr>
<td>Project</td>
<td>Workshop Project</td>
</tr>
<tr>
<td>Execution Environment</td>
<td>Default execution environment</td>
</tr>
<tr>
<td>Playbook</td>
<td><code>rhel/apache/apache_role_install.yml</code></td>
</tr>
<tr>
<td>Credentials</td>
<td>Workshop Credential</td>
</tr>
<tr>
<td>Limit</td>
<td>web</td>
</tr>
<tr>
<td>Options</td>
<td>Privilege Escalation</td>
</tr>
</table>

* Click **Save**

> **Warning**
>
> **Do not run the template yet!**
![Survey Q2](images/survey_q2.png)

#### Add the Survey

* In the Template, click the **Survey** tab and click the **Add** button.

* Fill out the following information:

<table>
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
<tr>
<td>Question</td>
<td>First Line</td>
</tr>
<tr>
<td>Answer Variable Name</td>
<td>first_line</td>
</tr>
<tr>
<td>Answer Type</td>
<td>Text</td>
</tr>
</table>

* Click **Save**
* Click the **Add** button

In the same fashion add a second **Survey Question**

<table>
<tr>
<th>Parameter</th>
<th>Value</th>
</tr>
<tr>
<td>Question</td>
<td>Second Line</td>
</tr>
<tr>
<td>Answer Variable Name</td>
<td>second_line</td>
</tr>
<tr>
<td>Answer Type</td>
<td>Text</td>
</tr>
</table>

* Click **Save**
* Click the **Survey Enabled** toggle button to turn on the Survey questions
5. Click **Save**.
6. Enable the survey by toggling the **Survey disabled** button to the on positon.

### Launch the Template

Now launch **Create index.html** job template by selecting the **Details** tab and clicking the **Launch** button.
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.

Before the actual launch the survey will ask for **First Line** and **Second Line**. Fill in some text and click **Next**. The **Preview** window shows the values, if all is good run the Job by clicking **Launch**.
![Survey Launch](images/survey_launch.png)

After the job has completed, check the Apache homepage. In the SSH console on the control host, execute `curl` against `node1`:
![Survey Review](images/survey_review.png)

Once the job completes, verify the Apache homepage by running the following `curl` command in the SSH console on the control host:

```bash
$ curl http://node1
Expand All @@ -229,8 +123,6 @@ $ curl http://node1
</body>
```

Note how the two variables where used by the playbook to create the content of the `index.html` file.

---
**Navigation**
<br>
Expand All @@ -240,5 +132,4 @@ Note how the two variables where used by the playbook to create the content of t
{% else %}
[Previous Exercise](../2.3-projects) - [Next Exercise](../2.5-rbac)
{% endif %}
<br><br>
[Click here to return to the Ansible for Red Hat Enterprise Linux Workshop](../README.md)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b615375

Please sign in to comment.