Bookmark this page

Guided Exercise: Creating Job Template Surveys to Set Variables for Jobs

  • Add a survey to an existing job template and launch a job using that survey.

Outcomes

  • Add a survey to an existing job template.

  • Launch a job using a survey from the automation controller web UI.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that automation controller is installed and configured with any necessary resources created in previous exercises.

[student@workstation ~]$ lab start job-survey

Procedure 5.2. Instructions

  1. Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.

  2. Add a survey to the DEV webservers setup job template.

    1. Navigate to ResourcesTemplates and then click the DEV webservers setup link.

    2. Click the Survey tab and then click Add.

    3. Add a single question to the survey, using the following information. When finished, click Save.

      FieldValue
      Question What version are you deploying?
      Description This version number is displayed at the bottom of the index page.
      Answer variable name deployment_version
      Answer type Text
      Required (selected)
      Minimum length 1
      Maximum length 40
      Default Answer v1.0
    4. Click Survey Disabled and verify that the label changes to Survey Enabled. The survey is now enabled.

      Important

      The survey is disabled by default. Make sure that you enable it.

  3. Clone the https://git.lab.example.com/git/my_webservers_DEV.git Git repository into the /home/student/git-repos directory.

    1. From a terminal, create the /home/student/git-repos directory if it does not already exist, and then change into it:

      [student@workstation ~]$ mkdir -p ~/git-repos/
      [student@workstation ~]$ cd ~/git-repos/
    2. Clone the https://git.lab.example.com/git/my_webservers_DEV.git repository and then change into the cloned repository:

      [student@workstation git-repos]$ git clone \
      > https://git.lab.example.com/git/my_webservers_DEV.git
      Cloning into 'my_webservers_DEV'...
      ...output omitted...
      [student@workstation git-repos]$ cd my_webservers_DEV
  4. Modify the ~/git-repos/my_webservers_DEV/templates/index.html.j2 Jinja2 template to use the variable from the survey.

    1. Edit the index.html.j2 template to add the following line to the bottom of the file:

      Deployment Version: {{ deployment_version }} <br>

      After you edit and save index.html.j2, the file contains the following content:

      Current Host: {{ ansible_facts['fqdn'] }} <br>
      Server list: <br>
      {% for host in groups['all'] %}
      {{ host }} <br>
      {% endfor %}
      Deployment Version: {{ deployment_version }} <br>
    2. Add, commit, and push the file to the remote Git repository:

      [student@workstation my_webservers_DEV]$ git add templates/index.html.j2
      [student@workstation my_webservers_DEV]$ git commit \
      > -m "Display Deployment Version on index page"
      [main 2c435c7] Display Deployment Version on index page
       1 file changed, 1 insertion(+)
      [student@workstation my_webservers_DEV]$ git push -u origin
      Enumerating objects: 7, done.
      Counting objects: 100% (7/7), done.
      Delta compression using up to 4 threads
      Compressing objects: 100% (4/4), done.
      Writing objects: 100% (4/4), 468 bytes | 468.00 KiB/s, done.
      Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
      To https://git.lab.example.com/git/my_webservers_DEV.git
         3b3341b..2c435c7  main -> main
  5. Update the local copy of the Git repository on automation controller for the My Webservers DEV project.

    1. Navigate to ResourcesProjects.

    2. On the same line as the My Webservers DEV project, click the Sync Project icon and wait for the Status column to display Successful.

    3. Click the Refresh project revision icon in the Revision column to update the revision version. The revision matches the last commit. You can verify this information with the following command:

      [student@workstation my_webservers_DEV]$ git log --pretty=format:'%h' -1
      2c435c7
  6. As a member of the Developers team, launch a job using the updated DEV webservers setup job template.

    1. Navigate to adminLogout in the upper-right corner to log out, and then log back in as daniel using redhat123 as the password.

    2. Navigate to ResourcesTemplates and then click the Launch Template icon for the DEV webservers setup job template. This opens the survey you just created and prompts for your input.

    3. Leave v1.0 in the text field and click Next followed by Launch to launch the job. This redirects you to a detailed status page of the running job.

    4. Briefly observe the live output of the running job.

    5. When the job is complete, confirm that the Status of the job in the Details tab is Successful.

  7. Verify that the web servers have been updated on servera.lab.example.com and serverb.lab.example.com.

    1. Open a web browser and navigate to http://servera.lab.example.com and http://serverb.lab.example.com in separate tabs. You should see this line at the bottom of both pages:

      ...output omitted...
      Deployment Version: v1.0

      Important

      If you complete the exercises in this course out of order, or if you repeat this exercise after completing later exercises, then your web browser might redirect requests to the HTTPS versions of http://servera.lab.example.com and http://server.lab.example.com. The redirection results in Unable to connect messages because the DEV webservers setup job template does not configure HTTPS.

      If this happens, then you can either clear your web browser cache or you can use the curl command to verify the content of the web servers.

  8. Navigate to danielLogout in the upper-right corner to log out of the automation controller web UI.

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish job-survey

This concludes the section.

Revision: do467-2.2-08877c1