Automating routine tasks with AWX

Although there are many facets to AWX that would require much more space than we have in this book, one particular one stands outthe automation of routine tasks. Routine tasks that Ansible could handle might include patching of servers, running some kind of compliance check or audit, or enforcing a security policy.

For example, you could write an Ansible playbook to ensure that the SSH daemon does not allow remote root logins as this is considered a good security practice. It is, of course, easy for any system administrator with root privileges to log in and turn this back on; however, running an Ansible playbook regularly to turn this off enforces it and ensures no-one (well-meaning or otherwise) turns it back on. The idempotent nature of Ansible changes means that where the configuration is already in place, Ansible will not make any changes, and hence running the playbook is safe, light on system resources, and non-disruptive.

If you wanted to do this with Ansible on the command line, you would need to create a cron job to run the ansible-playbook command regularly, along with all of the required parameters. This would mean having the SSH private keys installed on the server handling the automation, and means you have to keep track of which servers are running Ansible on a routine basis. This is not ideal for an enterprise where good practice is the byword of automation and ensures that everything keeps running smoothly.

Luckily, AWX can help us out here, too. To keep this example concise, we will reuse the LAMP stack example from the previous section of this chapter. In this scenario, we might want to schedule a one-off installation of the LAMP stack for a time when things are quiet, whereas for a routine task, it would be on an ongoing basis.

To set a schedule for this template, follow these steps:

  1. Click on Templates on the left-hand menu bar.
  2. Click on the template we created earlier.
  3. Click on the SCHEDULES button at the top of the pane.
  4. Click on the green + icon to add a new schedule to it.
  5. Set the appropriate start date and timeI will set mine a few minutes from now to demonstrate it in action.
  6. Also, set the appropriate timezone.
  7. Finally, select the REPEAT FREQUENCYin this example, I will choose None (run once), but note that other ongoing options are available from the drop-down list.
  8. Click on the green SAVE button to activate the schedule.

When you have completed the preceding steps, the resulting configuration screen should look something like the following:

Now, if you watch the Jobs pane, you should see your template start to run at the scheduled time. When you analyze the completed (or indeed running) job, you should see that it was launched by the name of the schedule you created earlier, rather than by the name of a user account such as admin (as we saw when we launched it manually). A screenshot is provided here that shows an example of a completed job that was launched by our Scheduled install schedule that we created earlier in this section:

If you want to see all scheduled jobs that are forthcoming on your AWX instance, you can simply click on the Schedules menu item on the left-hand menu bar, and a screen will load that lists all configured schedules in your AWX instance. For those of you familiar with Linux administration, this is akin to listing cron jobs. An example of such a screen is shown in the following screenshot:

This gives you a concise overview of all of the schedules you have created, without having to go into the individual configuration items themselves to edit them.

In this way, AWX supports not just interactive automation of your Linux environment, but also hands-off scheduled automation tasks too, hence increasing the power and flexibility of your automation solution.

It is hoped that this overview gives you an idea of the benefits that a tool such as AWX or Ansible Tower can bring to your enterprise, and why it is beneficial to supplement your Ansible automation with this.

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

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