Is there a way for “failed but expected” assertions, e.g. ones that cannot be handled by role validation to fail less noisily than usual failures. For example, with
- name: If a limit has been specified, ensure it includes localhost # for cooldown
run_once: true
when: ansible_limit is defined
assert:
that: ('localhost' in ansible_limit | split(','))
fail_msg: If a limit is specified with --limit [-l], it must include localhost
quiet: true
Which is because my playbook has a final play that has localhost to gather up results from all of the target hosts from the previous plays into a number of files.
If I specify -l host1,host2 rather than -l host1,host2,localhost (an easy mistake to make), I get
TASK [role_name : If a limit has been specified, ensure it includes localhost] *************************************************************************************************************************************
Saturday 19 September 2026 11:07:43 +0100 (0:00:00.077) 0:00:00.092 ****
[ERROR]: Task failed: Action failed: If a limit is specified with --limit [-l], it must include localhost
Origin: <path>:<line>:<column>
1 ---
2 - name: If a limit has been specified, ensure it includes localhost # for cooldown
^ column 3
fatal: [host1]: FAILED! =>
assertion: ('localhost' in ansible_limit | split(','))
changed: false
evaluated_to: false
msg: If a limit is specified with --limit [-l], it must include localhost
It would be good if there could be attribute on the task, similar to no_log, perhaps fail_quiet, that would give:
TASK [role_name : If a limit has been specified, ensure it includes localhost] *************************************************************************************************************************************
Saturday 19 September 2026 11:07:43 +0100 (0:00:00.077) 0:00:00.092 ****
[ERROR]: Task failed: Action failed: If a limit is specified with --limit [-l], it must include localhost
Origin: <path>:<line>:<column>
fatal: [host1]: FAILED! =>
assertion: ('localhost' in ansible_limit | split(','))
changed: false
evaluated_to: false
msg: If a limit is specified with --limit [-l], it must include localhost
or even
TASK [role_name : If a limit has been specified, ensure it includes localhost] *************************************************************************************************************************************
Saturday 19 September 2026 11:07:43 +0100 (0:00:00.077) 0:00:00.092 ****
[ERROR]: Task failed: Action failed: If a limit is specified with --limit [-l], it must include localhost
Origin: <path>:<line>:<column>
Although it would be most appropriate to assert I assume this would be much easier to implement as an attribute on any task (like no_log) rather than one on assert (like quiet)
Of course, another way of doing this would be good.