有時主機較多時,我們只想關注有問題的主機。
Ansible callback 插件中有一個 actionable
,官方描述為:
actionable - shows only items that need attention
即只輸出需要關注的部分。
但是 callback 插件只對 playbook 生效,如何對 Ad-hoc 起作用呢?
參考文檔:https://docs.ansible.com/ansible/2.6/plugins/callback.html#managing-adhoc
可以通過修改配置文件
[defaults]
bin_ansible_callbacks=True
或者修改環境變量來實現
export ANSIBLE_LOAD_CALLBACK_PLUGINS=1
這里我們通過環境變量的方式來進行,這樣比較輕量,無需修改文件
在運行 Ad-hoc 命令時,前面加上兩個參數即可:
ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ANSIBLE_STDOUT_CALLBACK=actionable
完整命令如下:
ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ANSIBLE_STDOUT_CALLBACK=actionable ansible all -m ping
另外,ansible 環境變量匯總見頁面:https://docs.ansible.com/ansible/2.6/reference_appendices/config.html#ansible-configuration-settings
參考:
- https://stackoverflow.com/questions/40239150/how-can-i-make-ansible-show-only-errors-in-execution
- https://docs.ansible.com/ansible/2.6/plugins/callback.html#callback-plugins
本文由博客一文多發平台 OpenWrite 發布!