how can I hide the ok: [web] output on terminal but display the msg on the terminal.
This is what I have in the ansible.cfg file. If I set display_ok_hosts=false, nothing will display on the terminal.
how can I hide the ok: [web] output on terminal but display the msg on the terminal.
This is what I have in the ansible.cfg file. If I set display_ok_hosts=false, nothing will display on the terminal.
Use the callback community.general.selective. See
shell> ansible-doc -t callback selective
Quoting:
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
tasks:
- getent:
database: passwd
- assert:
that:
- 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