Handling Conditional Checks in a Survey Workflow Without Job Failure

Hello colleagues,

I am currently facing an issue with a survey workflow in Ansible that requires conditional checks and subsequent tasks execution based on the survey results.

Here’s the scenario:

I have a survey that determines which of the two checks (or both) should be executed. Depending on the survey result, either check-useast, check-eucentral, or both need to be run. Upon successful execution of these checks, the next corresponding step (either adserver-useast or adserver-eucentral) should be executed.

This is the behavior I desire, and it works as expected. However, there is one issue. When only one region needs to be executed, the other check (which is not supposed to run) fails as expected but causes the job to be marked as failed. This is problematic because, in reality, only one route should be executed based on the survey results.

What I want to achieve is to make these checks non-determinant, meaning that the overall workflow result should reflect the execution of the appropriate templates regardless of the failed check for the unused route.

Here’s a visual representation of the workflow for better understanding:

Here I share the playbook of one of the two checks.

---
- name: Verify if useast is in the selection
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Check if useast is selected
      fail:
        msg: "useast not selected"
      when: "'useast' not in regions"
      register: useast_check

    - name: Debug output for useast
      debug:
        msg: "useast is selected"
      when: "'useast' in regions"

Could anyone provide guidance on how to configure the checks so that the job does not fail when one of the checks fails due to it not being required?

Thank you for your assistance!

Hi
Probably you should split your tasks into two differents playbook and so link your workflow check-useast to the corresponding playbook AND check-eucentral to the corresponding playbook too.

Doing that you’ll get only the playbook that pass the check to be executed.

Hi,

Thank you for your suggestion. I want to clarify that the second job in each branch is actually the same; it’s a single template that I want to deploy in two different zones. The problem is that each zone requires a different PEM file for the machines, and AWX can only handle one of them at a time. Therefore, my solution was to create two branches, each configured to deploy in the desired zone with all necessary settings pre-configured. This way, other teams using it don’t have to modify anything. They just select the zone in the survey and deploy. I want to avoid separating the workflow into different playbooks. I prefer to keep everything within the same workflow