how can I hide the ok: [web] output on terminal but display the msg on the terminal.

enter image description here

This is what I have in the ansible.cfg file. If I set display_ok_hosts=false, nothing will display on the terminal. enter image description here


1 Answer 1


Use the callback community.general.selective. See

shell> ansible-doc -t callback selective


This callback only prints tasks that have been tagged with print_action or that have failed.

For example, the playbook

shell> cat pb.yml
- hosts: web
  gather_facts: false


    - getent:
        database: passwd
    - assert:
          - getent_passwd._apt.5 == '/usr/sbin/nologin'
          - getent_passwd._rpc.5 == '/usr/sbin/nologin'
          - getent_passwd._chrony.5 == '/usr/sbin/nologin'
        success_msg: "[PASSED] - Ensure system accounts are non-login"
      tags: [print_action]

shows the output of all tasks when default callback is used

shell> ANSIBLE_STDOUT_CALLBACK=default ansible-playbook pb.yml

PLAY [web] ***********************************************************************************

TASK [getent] ********************************************************************************
ok: [web]

TASK [assert] ********************************************************************************
ok: [web] => {
    "changed": false,
    "msg": "[PASSED] - Ensure system accounts are non-login"

PLAY RECAP ***********************************************************************************
web: ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

The output is limited to the enabled task when the selective callback is used

shell> ANSIBLE_STDOUT_CALLBACK=selective ansible-playbook pb.yml
# assert ******************************************************************************************************************
  * web                        - changed=False --------------------------------------------------
    [PASSED] - Ensure system accounts are non-login

# STATS *******************************************************************************************************************
web: ok=2   changed=0   failed=0    unreachable=0   rescued=0   ignored=0
  • Is there another way of doing this? I want to run the playbook with no additional text.
    – JakePaul
    Sep 8, 2022 at 9:00
  • 1
    Then use ansible-runner and display what you want. As a hint see my wrapper. Sep 8, 2022 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .