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