AWX - Limit - Check in the role if there are no play_hosts?

I put this under AWX, because of the way the Limit functionality makes the job fail if it cannot find any matching hosts.

Is it possible to ignore this checking in AWX and I do the error handling in the role itself?

Something like:

- name: Check play_hosts length
  ansible.builtin.meta: end_play
  when: play_hosts|length < 1
  delegate_to: localhost

We have some workflows that check for patchwaves attributes of hosts. In some regions no hosts are scheduled for those patchwaves. I would still like to keep the workflows generic in case someone changes an attribute for a host in the inventory and then it would find one. At the moment those just fail with:

[WARNING]: Could not match supplied host pattern, ignoring: azure_loc_ukwest
ERROR! Specified inventory, host pattern and/or --limit leaves us with no hosts to target.

And this happens before the role is even executed. It does not help to add localhost to the hosts variable in the role, because the role is not even loaded in this case.

Hello @disi,
Thank you for providing this information. We wanted to check in and see if you were able to get this resolved on your end.

We have also tagged this to bring it to the attention of Ansible-Core, as they may be better able to assist you with this matter.

it might be possible to setup a workflow node that runs before any others, with a task similar to what you posted. Just a single task delegates to localhost, and introspects the rest of the inventory. Only pass on the other inventory hosts to the rest of the workflow nodes if this first one passes

1 Like

I would need to use no Limit and then in the role the AWX API to check if it finds any hosts, I guess.
I also tried regex, but there is no real β€œAND” option. Something like:

~(.*(?=.*tag_patchwave_2.*).*(?=.*azure_loc_westeurope.*).*|.*(?=.*tag_patchwave_2.*).*(?=.*azure_loc_ukwest.*).*|US2AZAWXVMP01)

This should return a few, but it always returns US2AZAWXVMP01.

But you are correct, I can run some job and if that fails, stop the rest of the workflow :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.