Workshop Exercise - Wrap up

Read this in other languages:
uk English, japan日本語, brazil Portugues do Brasil, france Française, Español Español.

Table of Contents


This is the final challenge where we try to put most of what you have learned together.


Let’s set the stage

Your operations team and your application development team likes what they see in Ansible automation controller. To really use it in their environment they put together these requirements:

The Git Repository

All code is already in place - this is a automation controller lab after all. Check out the Workshop Project git repository at There you will find the playbook webcontent.yml, which calls the role role_webcontent.

Compared to the previous Apache installation role there is a major difference: there are now two versions of an index.html template, and a task deploying the template file which has a variable as part of the source file name:


<h1>This is a development webserver, have fun!</h1>
{{ dev_content }}


<h1>This is a production webserver, take care!</h1>
{{ prod_content }}


- name: Deploy index.html from template
    src: "{{ stage }}_index.html.j2"
    dest: /var/www/html/index.html
  notify: apache-restart

Prepare Inventory

There is of course more then one way to accomplish this, but for the purposes of this lab, we will use Ansible automation controller.

Within Resources -> Inventories and select ‘Workshop Inventory’.

Within the Groups tab, click the Add button and create a new inventory group labeled Webserver and click Save.

Within the Details tab of the Webserver group, click on Edit. Within the Variables textbox define a variable labeled stage with the value dev and click Save.

stage: dev

Within the Details tab of the Webserver group, click the Hosts tab, click the Add button and Add existing host. Select node1, node2, node3 as the hosts to be part of the Webserver inventory.

Within Resources -> Inventories, select the Workshop Inventory. Click on the Hosts tab and click on node2. Click on Edit and add the stage: prod variable in the Variables window. This overrides the inventory variable due to order of operations of how the variables are accessed during playbook execution.

Within the Variables textbox define a variable labeled stage with the value of prod and click Save.

ansible_host: <IP_of_node2>
stage: prod


Make sure to keep the three dashes that mark the YAML start and the ansible_host line in place!

Create the Template

Within Resources -> Templates, select the Add button and Add job template as follows:

Parameter Value
Name Create Web Content
Job Type Run
Inventory Workshop Inventory
Project Workshop Project
Execution Environment Default execution environment
Playbook rhel/apache/webcontent.yml
Credentials Workshop Credential
Variables dev_content: "default dev content", prod_content: "default prod content"
Options Privilege Escalation

Click Save.

Run the template by clicking the Launch button.

Check the Results

This time we use the power of Ansible to check the results: execute uri to get the web content from each node, orchestrated by an Ansible playbook labeled check_url.yml


We are using the ansible_host variable in the URL to access every node in the inventory group.

- name: Check URL results
  hosts: web

    - name: Check that you can connect (GET) to a page and it returns a status 200
        url: "http://{{ ansible_host }}"
        return_content: yes
      register: content

    - debug:
       var: content.content
[student@ansible-1 ~]$ ansible-navigator run check_url.yml -m stdout

Snippet of output:

TASK [debug] *******************************************************************
ok: [node1] => {
    "content.content": "<body>\n<h1>This is a development webserver, have fun!</h1>\ndev wweb</body>\n"
ok: [node2] => {
    "content.content": "<body>\n<h1>This is a production webserver, take care!</h1>\nprod wweb</body>\n"
ok: [node3] => {
    "content.content": "<body>\n<h1>This is a development webserver, have fun!</h1>\ndev wweb</body>\n"

Add Survey

Parameter Value
Question What should the value of dev_content be?
Answer Variable Name dev_content
Answer Type Text

In the same fashion add a second Survey Question

Parameter Value
Question What should the value of prod_content be?
Answer Variable Name prod_content
Answer Type Text

Check the results again from your automation controller host. We will use the dedicated uri module within an Ansible playbook. As arguments it needs the actual URL and a flag to output the body in the results.

[student@ansible-1 ~]$ ansible-navigator run check_url.yml -m stdout



Solution Not Below

You have done all the required configuration steps in the lab already. If unsure, just refer back to the respective chapters.

The End

Congratulations, you finished your labs! We hope you enjoyed your first encounter with Ansible automation controller as much as we enjoyed creating the labs.

Previous Exercise

Click here to return to the Ansible for Red Hat Enterprise Linux Workshop