Hi all,
I’m running AWX on single node k3s cluster and need to fail a job if “Could not match supplied host pattern, ignoring:…” basically hook into v2_playbook_on_no_hosts_matched
I have a callback_plugin that basically does that a brute force way by exiting 1 but is there any other way to mark the job failed… because if I rise error the job is still marked as Successful in AWX which is nonsense.
from ansible.plugins.callback import CallbackBase
from ansible.errors import AnsibleError
from ansible import constants as C
class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = ‘notification’
CALLBACK_NAME = ‘fail_on_no_hosts’
def v2_playbook_on_no_hosts_matched(self):
fail the Ansible tower Job
self._display.error(“No hosts matched”)
exit(1)