Read this in other languages:
English, 日本語, Portugues do Brasil, Française, Español.
- Objective
- Guide
- Setup Git Repository
- Create the Project
- Create a Job Template and Run a Job
- Challenge Lab: Check the Result
- What About Some Practice?
An Ansible Tower 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 Tower, including Git, Subversion, and Mercurial.
This exercise covers
- Understanding and using an Ansible Tower Project
- Using Ansible Playbooks kept in a Git repository.
- Creating and using an Ansible Job Template
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: all
tasks:
- name: latest Apache version installed
yum:
name: httpd
state: latest
- name: latest firewalld version installed
yum:
name: firewalld
state: latest
- name: firewalld enabled and running
service:
name: firewalld
enabled: true
state: started
- name: firewalld permits http service
firewalld:
service: http
permanent: true
state: enabled
immediate: yes
- name: Apache enabled and running
service:
name: httpd
enabled: true
state: started
Tip
Note the difference to other Playbooks you might have written! Most importantly there is no
become
andhosts
is set toall
.
To configure and use this repository as a Source Control Management (SCM) system in Tower you have to create a Project that uses the repository
-
Go to RESOURCES → Projects in the side menu view click the green + button. Fill in the form:
Parameter Value NAME Workshop Project ORGANIZATION Default SCM TYPE Git
Now you need the URL to access the repo. Go to the Github repository mentioned above, choose the green Clone or download button on the right, click on Use https and copy the HTTPS URL.
Note
If there is no Use https to click on, but a Use SSH, you are fine: just copy the URL. The important thing is that you copy the URL starting with https.
Enter the URL into the Project configuration:
Parameter | Value |
---|---|
SCM URL | https://github.com/ansible/workshop-examples.git |
SCM UPDATE OPTIONS | Tick the first three boxes to always get a fresh copy of the repository and to update the repository when launching a job |
- Click SAVE
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 Get latest SCM revision icon to the right of the Project.
After starting the sync job, go to the Jobs view: there is a new job for the update of the Git repository.
A job template is a definition and set of parameters for running an Ansible job. Job templates are useful to execute the same job many times. So before running an Ansible Job from Tower you must create a Job Template that pulls together:
-
Inventory: On what hosts should the job run?
-
Credentials What credentials are needed to log into the hosts?
-
Project: Where is the Playbook?
-
What Playbook to use?
Okay, let’s just do that: Go to the Templates view, click the button and choose Job Template.
Tip
Remember that you can often click on magnfying glasses to get an overview of options to pick to fill in fields.
Parameter | Value |
---|---|
NAME | Install Apache |
JOB TYPE | Run |
INVENTORY | Workshop Inventory |
PROJECT | Workshop Project |
PLAYBOOK | rhel/apache/apache_install.yml |
CREDENTIAL | Workshop Credentials |
LIMIT | web |
OPTIONS | tasks need to run as root so check **Enable privilege escalation** |
- Click SAVE
You can start the job by directly clicking the blue LAUNCH 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:
Since this might take some time, have a closer look at all the details provided:
-
All details of the job template like inventory, project, credentials and playbook are shown.
-
Additionally, the actual revision of the playbook is recorded here - this makes it easier to analyse job runs later on.
-
Also the time of execution with start and end time is recorded, giving you an idea of how long a job execution actually was.
-
On the right side, the output of the playbook run is shown. Click on a node underneath a task and see that detailed information are provided for each task of each node.
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 SCM update was started. This is the Git update we configured for the Project on launch!
Time for a little challenge:
- Use an ad hoc command on both hosts to make sure Apache has been installed and is running.
You have already been through all the steps needed, so try this for yourself.
Tip
What about
systemctl status httpd
?
Warning
Solution Below
-
Go to Inventories → Workshop Inventory
-
In the HOSTS view select all hosts and click RUN COMMANDS
-
Fill out the following:
Parameter | Value |
---|---|
MODULE | command |
ARGUMENTS | systemctl status httpd |
MACHINE CREDENTIALS | Workshop Credentials |
- Click LAUNCH
Navigation
Previous Exercise - Next Exercise
Click here to return to the Ansible for Red Hat Enterprise Linux Workshop