Select Page

Ansible – AWX|Tower State handling on Workflows

by | Apr 27, 2021 | Ansible, Icinga, NETWAYS, Python

The Ansible Tower or its upstream AWX provides an easy to use GUI to handle Ansible tasks and schedules. Playbooks are configured as templates and as the name suggests, they can be modified to the needs, extended by variables, a survey or tags.

Furthermore those templates can be logically grouped, connected and visualised in Workflows.

The downside to those Workflows, all playbooks affected by this are executed separately and can’t access each others variables. On first glance we maybe only spot that we can define variables for the whole workflow but those are not changeable throughout the flow.

But there is a solution, which is the module set_stats. This module allows to save or accumulate variables and make them available for other playbooks within the workflow.

As an example we could use the monitoring environment when setting downtimes.

workflow

As a downtime is created before a maintenance and should be gone when the maintenance is done. This creates a dependency on the first task, which can be solved as we save the result of the first tasks with the set_stats module.


      - name: schedule downtimes
        icinga2_downtimes:
          state: "{{ downtime_icinga_state | default('present') }}"
          host: ***
          author: "{{ icinga2_downtimes_author | default('ansible_downtime') }}"
          comment: "{{ icinga2_downtimes_comment | default('Downtime scheduled by Ansible') }}"
          duration: "{{ icinga2_downtimes_duration | default(omit) }}"
        register: content
 
      - set_stats:
          data:
            downtime: "{{ content }}"

The content of the data will be now available to all playbooks included by the workflow. The variable is also shown as artefacts in the GUI.

artefacts

Keep in mind that the variable will be part of the extra variables for all other playbooks. As covered in the variable precedence it will overwrite any other variable named the same.

With this module you can reorganise your playbooks and connect them in workflows. This allows you to have a more flexible automation than before.

Check out our Blog for more awesome posts and if you need help with Ansible send us a message or sign up for one of our trainings!

Thilo Wening
Thilo Wening
Consultant

Thilo hat bei NETWAYS mit der Ausbildung zum Fachinformatiker, Schwerpunkt Systemadministration begonnen und unterstützt nun nach erfolgreich bestandener Prüfung tatkräftig die Kollegen im Consulting. In seiner Freizeit ist er athletisch in der Senkrechten unterwegs und stählt seine Muskeln beim Bouldern. Als richtiger Profi macht er das natürlich am liebsten in der Natur und geht nur noch in Ausnahmefällen in die Kletterhalle.
More posts on the topicAnsible | Icinga | NETWAYS | Python

Variablen mergen mit Ansible

  Ansible kann Variable standardmäßig nicht mergen (miteinander vereinen, ineinander übergeben), sondern nur an verschiedenen Stellen überschreiben. Dies ist  bei manchen Anwendungsfällen unpraktisch, unübersichtlich und fehleranfällig wie z. B. beim ausrollen...

Monthly Snap April 2021

April was the month of easter eggs, and was, as always, the month where spring, summer and winter shook hands. Despite that several colleagues took a few days off around easter, we have a good and varied selection of blogs for you:   Stackconf   Katja made...

Let’s meet again – OSMC 2021

Good news! We’re happy to announce that the Open Source Monitoring Conference will take place this year again. Based on a survey with a resulting majority of two thirds of former OSMC attendees we are excited to organize our event again and can't wait to welcome you...

Veranstaltungen

Tue 18

Icinga 2 Fundamentals Training | Online

May 18 @ 09:00 - May 21 @ 17:00
Jun 15

stackconf online

June 15 - June 17
Jun 22

Ansible Fundamentals Training | Online

June 22 @ 09:00 - June 24 @ 17:00
Jun 22

Kubernetes Quick Start | Online

June 22 @ 09:00 - 17:00
Jun 25

Ansible AWX (Tower) Training | Online

June 25 @ 09:00 - 17:00