# "New" attribute to supress the task trace before a failing task

**URL:** <https://forum.ansible.com/t/new-attribute-to-supress-the-task-trace-before-a-failing-task/46328>\
**Category:** Get Help\
**Created:** [September 19, 2026, 10:17am UTC](https://forum.ansible.com/t/new-attribute-to-supress-the-task-trace-before-a-failing-task/46328 "2026-09-19T10:17:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsgsh](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@tsgsh](https://forum.ansible.com/u/tsgsh)\
**Post date:** [September 19, 2026, 10:17am UTC](https://forum.ansible.com/t/new-attribute-to-supress-the-task-trace-before-a-failing-task/46328/1 "2026-09-19T10:17:55Z")

</div>

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

```auto
- 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

```auto
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:

```auto
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

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

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 20, 2026, 3:34am UTC](https://forum.ansible.com/t/new-attribute-to-supress-the-task-trace-before-a-failing-task/46328/2 "2026-09-20T03:34:36Z")

</div>

> [@tsgsh](#):
>
> 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`

FWIW, `--limit` selects `hosts` in a playbook. It does not select available inventory. For example, the complete inventory

```auto
> cat hosts/localhost 
localhost ansible_connection=local

> cat hosts/www
[www]
www_01
www_02
www_03

```

is available

```auto
> ansible-inventory -i hosts --graph
@all:
  |--@ungrouped:
  | |--localhost
  |--@www:
  | |--www_01
  | |--www_02
  | |--www_03

```

As a result, `localhost` is available to delegate to

```yaml
- hosts: all
  gather_facts: false
  tasks:
    - set_fact:
        log: "Running on {{ inventory_hostname }} ..."

    - name: Gather results from target hosts
      delegate_to: localhost
      run_once: true
      block:
        - debug:
            msg: |
              {% for h in ansible_limit | split(',') %}
              {{ h }}: {{ hostvars[h]['log'] | d('UNDEF') }}
              {% endfor %}

```

For example,

```yaml
> ansible-playbook -i hosts -l www_01,www_02 pb.yml 

PLAY [all] **********************************************************************************

TASK [set_fact] *****************************************************************************
ok: [www_01]
ok: [www_02]

TASK [debug] ********************************************************************************
ok: [www_01 -> localhost] => 
    msg: |-
        www_01: Running on www_01 ...
        www_02: Running on www_02 ...

PLAY RECAP **********************************************************************************
www_01 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   
www_02 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 

```

---

<div class="post-metadata">

**Author:** ![tsgsh](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@tsgsh](https://forum.ansible.com/u/tsgsh)\
**Post date:** [September 20, 2026, 8:25am UTC](https://forum.ansible.com/t/new-attribute-to-supress-the-task-trace-before-a-failing-task/46328/3 "2026-09-20T08:25:34Z")

</div>

Ah, it never occurred to me that I could make localhost explicit in the inventory. I’ve always used it implicitly. That solves the problem for this case, Thanks.

I still have other cases where a quieter assert might be useful.
