![Ansible 隐藏正常:[web] 输出但显示消息](https://linux22.com/image/210422/Ansible%20%E9%9A%90%E8%97%8F%E6%AD%A3%E5%B8%B8%EF%BC%9A%5Bweb%5D%20%E8%BE%93%E5%87%BA%E4%BD%86%E6%98%BE%E7%A4%BA%E6%B6%88%E6%81%AF.png)
答案1
使用回调社区.一般.选择性。看
shell> ansible-doc -t callback selective
引用:
此回调仅打印已标记
print_action
或已失败的任务。
例如,剧本
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]
显示所有任务的输出默认使用回调
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
输出仅限于启用的任务时可选择的使用回调
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