Header background

Set up Ansible Tower with Dynatrace to enable your self-healing applications

Successful development, deployment, operation, and maintenance of complex software systems built on cloud-based infrastructure can be a huge challenge for DevOps. Software outages due to errors or infrastructure failures often seem unavoidable.

Dynatrace, however, keeps your digital business up and running by not only monitoring your applications, services, and infrastructure, but by automatically taking action when problems are detected.

Connect Ansible Tower to Dynatrace

This blog post explains how to set up Ansible Tower, the automation platform powered by Red Hat, and how to connect Ansible Tower to Dynatrace to trigger automated remediation actions and enable self-healing applications.

We’ll guide you through the installation process and show you the commands and settings you need to get up and running with Ansible Tower.

You’ll learn

  • How to set up Ansible Tower in just a few steps.
  • How to configure Ansible Tower to connect with Dynatrace to enable self-healing applications.

We’ll also take a look at a short demo application that highlights the power of this toolchain.

Prerequisites

For demonstration purposes, we’ll set up Ansible Tower on Ubuntu Linux running in AWS. If you’re using Vagrant, you’ll find Vagrant setup instructions in an earlier post. If you choose another supported OS, know that these Ubuntu Linux instructions won’t apply.

Set up Ansible

To use Ansible Tower, you first have to set up the underlying Ansible engine. On your Ubuntu installation, run the following commands:

$ apt-get install software-properties-common
$ apt-add-repository ppa:ansible/ansible
$ apt-get update
$ apt-get install ansible

Set up Ansible Tower

Once you’ve installed Ansible, set up Ansible Tower, the tool used to connect to Dynatrace.

  1. Download and extract the Ansible Tower installer:
    $ curl -o ansible-tower-setup-latest.tar.gz http://releases.ansible.com/ansible-tower/setup/ansible-tower-setup-latest.tar.gz
    $ tar xvzf ansible-tower-setup-latest.tar.gz
    $ cd ansible-tower-setup-<tower_version>
  2. Open the inventory file with a text editor and change the corresponding lines below to set the passwords for your Ansible admin, PostgreSQL database, and RabbitMQ.
    $ nano inventory
    ### set passwords to 
    ### admin_password, pg_password, rabbitmq_password
  3. Run the installer script with using Ansible admin username and password you defined.
    $ ANSIBLE_SUDO=True ./setup.sh

    Installation may take a while, so grab a cup of coffee or watch one of the videos on the Dynatrace YouTube channel.

  4. Once you’ve installed Ansible Tower, sign in, and use your browser to connect to your Ansible Tower installation.
  5. Before you set up a new project, save your credentials (GitHub passwords and SSH keys) so you can easily reuse them across projects. To do this, navigate to Settings ► Credentials and add:
    • GitHub password for your GitHub repository for check out
    • An SSH key for the VM to connect to (the VM where you want to enable your self-healing applications)

Create a project

To set up the project for this demo

  1. Navigate to the Create Project page.
    Use the password stored in GitHub to check out the repository that contains the required source files.
  2. Define an inventory that contains the host on which we want to deploy our source from the GitHub repository. Click the Host section in your environment and add a new host (IP address or host name). This is the environment where your applications will be deployed.
  3. Create a template to define the actions that should be followed when the template is triggered by an external or internal source.
    In this example, we’ll:

    • Run the template (Trigger Rollback) and execute the playbook (site.yaml), which is stored in the GitHub repository. The playbook defines the actions that are to be taken when executing this job template.
    • Define an inventory (Demo Inventory) where the required credentials and the project can be found.
    • Assign a job tag (rollback) so you can execute only the tagged parts of the playbook.


    Once you’ve saved your job template, run it by clicking the corresponding rocket button (🚀) in the list of templates.
    If you hover over templates in this list, you’ll see the template IDs in your status bar. You’ll need a template job ID to call a job template with the API.

Connect Ansible Tower to Dynatrace

To enable applications to heal themselves when errors occur, you need the combined powers of Dynatrace (to auto-detect problems in real-time) and Ansible Tower (to run remediation tasks and bring applications back up following remediation).

  1. Sign in to your Dynatrace account.
  2. Select Settings from the navigation menu.
  3. Expand Integration and select Problem notifications to display the Problem notification setup page.
  4. Click Set up notifications and select Custom integration to open the Set up custom integration page.
  5. Type in a Name for the integration (for example, Ansible Tower).
  6. Paste the URL of your Ansible Tower REST API into the Webhook URL text field. For example, http://your-ansible-url.com/api/v2/job_templates/<your-job-id>/launch/.
    Be sure to you use your own job ID and don’t forget the slash at the end of the URL.
  7. Click Create basic authorization header.
    You’ll need the credentials of your Ansible Tower installation to allow access to your API. You won’t need a payload, so delete everything between the brackets in the Custom payload text field.

With this configuration complete, your Ansible Tower installation will be notified whenever Dynatrace detects a problem. Ansible Tower can then start remediation actions to automatically bring your applications back up and reduce your downtime.

You can also set up dedicated alerting profiles based on tags to fine-tune problem notifications in your integration.

Example use case

Suppose you deploy a new version of your web application and no errors are detected during deployment. Let’s say that you then discover a performance decrease in production that indicates there are undetected problems in the new version. Thanks to Dynatrace, such problems will be detected and reported with the help of our smart baselining as soon as several users are affected by the problem. With your Ansible Tower integration in place, Dynatrace will alert your Ansible Tower, and send you a problem notification in order to start your auto-remediation.

Within Ansible Tower, a predefined playbook will be triggered to roll back the application and bring the stable previous version of your application back online. Now you can resolve the performance decrease in the new version, using Dynatrace AI-driven root-cause analysis to guide your developers in understanding the issue. In the example below, a bug has been identified in the JavaScript code.

In brief:

      • Dynatrace detected a performance problem and forwarded it to Ansible Tower.
      • Ansible Tower executed a playbook and rolled the website back to the prior (stable) version.
      • The website was up and performing well again with no manual user intervention.

Conclusion

In this blog post

      • You learned how to set up an Ansible Tower installation in just a few steps.
      • You learned how to configure Ansible Tower and connect it with Dynatrace to create a powerful tool-chain that enables self-healing applications.
      • You saw a demo workflow illustrating how Ansible Tower and Dynatrace can be used in combination.

But this was just one example. There are many other scenarios in which you can benefit by connecting your Dynatrace monitoring with your automation platforms. Let me (@jetzlstorfer) know your scenario.