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.
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.
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!

0 Kommentare