一段时间以来,我一直在使用human_log.py
回调插件(https://github.com/n0ts/ansible-human_log或https://gist.github.com/cliffano/9868180)。任务运行时,它会显示对调试有用的信息:
TASK [server : Install nginx] ************************************************
ok: [192.168.1.2]
{ '_ansible_no_log': False,
'_ansible_parsed': True,
'cache_update_time': 1548736000,
'cache_updated': True,
'changed': False,
'invocation': { 'module_args': { 'allow_unauthenticated': False,
'autoclean': False,
'autoremove': False,
'cache_valid_time': 0,
'deb': None,
'default_release': None,
'dpkg_options': 'force-confdef,force-confold',
'force': False,
'force_apt_get': False,
'install_recommends': None,
'name': 'nginx-extras',
'only_upgrade': False,
'package': ['nginx-extras'],
'purge': False,
'state': 'present',
'update-cache': True,
'update_cache': True,
'upgrade': None}}}
我最近意识到Ansible stdout_callback
选项的存在。例如,在ansible.cfg
中:
[defaults]
stdout_callback = debug # or json, or yaml, etc.
# Alternative method: stdout_callback can be set as an environmental variable instead.
# For example: ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook tasks.yml
设置stdout_callback = debug
后,输出为:
TASK [server : Install nginx] ****************
ok: [192.168.1.2] => {
"cache_update_time": 1548738000,
"cache_updated": true,
"changed": false
}
有一种官方的方式可以在输出中显示更多信息,这很好,但是官方的插件有一个明显的遗漏:invocation
和module_args
丢失了。输出未显示调用该模块的参数。
是否可以在不使用第三方插件(例如human_log.py
)的情况下在输出中显示模块参数?
(参考:官方stdout_callback
插件的完整列表在这里:https://docs.ansible.com/ansible/2.7/plugins/callback.html#plugin-list。注意:这些插件仅在使用详细标志[{{1 }}])
答案 0 :(得分:0)
答案 1 :(得分:0)
以ansible-playbook
的详细程度执行-vvv
会显示invocation
参数,即使使用默认的标准输出回调也是如此。