Score:0

Passing variable to next playbook in awx workflow

mu flag

I'm having difficulties with the following setup:

  • AWX deployed in a self hosted k8s cluster
  • Playbooks are using the AWX-EE
  • Playbooks are executed in a workflow template as follows:

START -> 1. EC2 Inventory Sync -> 2. Playbook Repo Sync -> 3. Playbook Based EC2-Instance Creation (Job) -> 4. EC2 Inventory Sync -> 5. Run Playbook To Apply Roles

In case it is not self-explanatory: I'm trying to launch instances in aws and then provide them their corresponding system configuration.

The workflow template is configured with a survey, which asks the user for a customer id, ec2 instance class and environment ("mxenv"). From this point, the first playbook (3.) generates a hostname and saves it to the variable ("vpc_hostname"). I want this variable to be available in step 5.

So far I tried

(yaml file from step 3, excerpt)

  - ansible.builtin.set_fact:
      vpc_hostname: "{{ customer_id }}-frontend-01.{{ mxenv }}.example.com"
    delegate_to: localhost
    delegate_facts: true
  - ansible.builtin.set_stats:
      data:
        vpc_hostname: "{{ vpc_hostname }}"
      per_host: no

yaml file from step 5 (excerpt)

- name: Provisioning new instance starts now.
  hosts: "{{ tower_job_launch_data.artifacts.vpc_hostname }}"
  remote_user: loginuser
  become: true
  roles:
    - network

- name: Network settings done, applying software and system configuration
  hosts: "{{ tower_job_launch_data.artifacts.vpc_hostname }}"
  remote_user: loginuser
  become: true
  roles:
    - baseinfra
    - frontend

In the last file, I also tried

  hosts: "{{ workflow_job_artifacts.vpc_hostname }}"

as well as this in the first file:

      tower_job_launch_data:
        artifacts:
          vpc_hostname: "{{ vpc_hostname }}"

However, the artifacts section shown in the job overview in the gui remains empty after it failed and I'm left with this error:

ERROR! The field 'hosts' has an invalid value, which includes an undefined variable. The error was: 'tower_job_launch_data' is undefined. 'tower_job_launch_data' is undefined
The error appears to be in '/runner/project/post-frontend-launch.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Provisioning new instance starts now.
  ^ here

Sitting in front of this for hours now, I'm quite clueless, also, I'm new to AWX - please ask anything that you need to get a sufficient overview :)

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.