Integrating AWX with your first playbook

There is a basic four-stage process involved in getting a playbook to run from AWX, and once this is understood, it paves the way for more advanced usage and fuller integration in an enterprise environment. In this part of the chapter, we will master these four stages in order to get to the stage where we can run our first simple playbook, and this will give us the building blocks to move forwards with AWX in confidence. The four stages are as follows:

  1. Define a project.
  2. Define an inventory.
  3. Define credentials.
  4. Define a template.

The first three stages can be performed in any order, but the template mentioned in the final stage pulls together the three previously-created facets, and so, it must be defined last. Also, note that there does not need to be a one-to-one relationship between these items—several templates can be created from one project, as is also the case for inventories and credentials.

Before we get started, we need a simple playbook for use in our examples as we go through this part of the chapter. First of all, on the AWX host, create a folder for the project—if you used the recommended path suggested earlier in the chapter, this will be /var/lib/awx/projects.

Every locally hosted project must have its own folder, so let's create one here:

sudo mkdir /var/lib/awx/projects/mastery

Now place the following example code into this folder as example.yaml:

---
- name: AWX example playbook
hosts: all
gather_facts: false

tasks:
- name: Create temporary directory
file:
path: /tmp/mastery
state: directory

- name: Create a file with example text
lineinfile:
path: /tmp/mastery/mastery.txt
line: 'Created with Ansible Mastery!'
create: yes

With this done, we can proceed to defining a project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.255.87