Workshop Exercise - Projects & Job Templates

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

Table Contents

Objective

An Ansible automation controller Project is a logical collection of Ansible playbooks. You can manage your playbooks by placing them into a source code management (SCM) system supported by automation controller such as Git or Subversion.

This exercise covers:

Guide

Setup Git Repository

For this demonstration, we will use playbooks stored in a Git repository:

https://github.com/ansible/workshop-examples

A playbook to install the Apache web server has already been committed to the directory rhel/apache, apache_install.yml:

---
- name: Apache server installed
  hosts: web

  tasks:
  - name: latest Apache version installed
    ansible.builtin.yum:
      name: httpd
      state: latest

  - name: latest firewalld version installed
    ansible.builtin.yum:
      name: firewalld
      state: latest

  - name: firewalld enabled and running
    ansible.builtin.service:
      name: firewalld
      enabled: true
      state: started

  - name: firewalld permits http service
    ansible.builtin.firewalld:
      service: http
      permanent: true
      state: enabled
      immediate: yes

  - name: Apache enabled and running
    ansible.builtin.service:
      name: httpd
      enabled: true
      state: started

Tip

Note the difference from other playbooks you might have written! Most importantly there is no become and hosts is set to web.

To configure and use this repository as a Source Control Management (SCM) system in automation controller you have to create a Project that uses the repository

Create the Project

Parameter Value
Name Workshop Project
Organization Default
Execution Environment Default execution environment
Source Control Type Git

Enter the URL into the Project configuration:

Parameter Value
Source Control URL https://github.com/ansible/workshop-examples.git
Options Select Clean, Delete, Update Revision on Launch to request a fresh copy of the repository and to update the repository when launching a job.

The new project will be synced automatically after creation. But you can also do this manually: Sync the Project again by selecting the ‘Sync project’ blue button.

Project Sync

After starting the sync job, go to the Jobs view, and you’ll find the job doing the project update.

Create a Job Template and Run a Job

A job template allows you to run an automation job. In order to run any type of automation, a job template must be created. A job template consists of knowning the following information:

To create a Job Template, go to the Automation Execution -> Templates view,click the Create template button and choose Create job template.

Tip

Remember that you can often click on the question mark with a circle to get more details about the field.

Parameter Value
Name Install Apache
Job Type Run
Inventory Workshop Inventory
Project Workshop Project
Playbook rhel/apache/apache_install.yml
Execution Environment Default execution environment
Credentials Workshop Credential
Limit web
Options tasks need to run as root so check **Privilege Escalation**

You can start the job by directly clicking the blue Launch template button, or by clicking on the rocket in the Job Templates overview. After launching the Job Template, you are automatically brought to the job overview where you can follow the playbook execution in real time.

Template Details template details

Job Run job_run

Since this might take some time, have a closer look at all the details provided:

After the Job has finished go to the main Jobs view: All jobs are listed here, you should see directly before the Playbook run an Source Control Update was started. This is the Git update we configured for the Project on launch!

Challenge Lab: Check the Result

Time for a little challenge:

You have already been through all the steps needed, so try this for yourself.

Tip

What about systemctl status httpd?

Warning

Solution Below

Within the Details window, select Module command, in Arguments type systemctl status httpd 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.

Tip

The output of the results is displayed once the command has completed.


Navigation
Previous Exercise - Next Exercise

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