如何使用官方的stdout_callback插件显示调用模块参数?

时间:2019-01-29 05:26:07

标签: ansible ansible-2.x

一段时间以来,我一直在使用human_log.py回调插件(https://github.com/n0ts/ansible-human_loghttps://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
}

有一种官方的方式可以在输出中显示更多信息,这很好,但是官方的插件有一个明显的遗漏:invocationmodule_args丢失了。输出未显示调用该模块的参数。

是否可以在不使用第三方插件(例如human_log.py)的情况下在输出中显示模块参数?

(参考:官方stdout_callback插件的完整列表在这里:https://docs.ansible.com/ansible/2.7/plugins/callback.html#plugin-list。注意:这些插件仅在使用详细标志[{{1 }}])

2 个答案:

答案 0 :(得分:0)

我认为这不是请求此类功能的位置。 您应该转到官方页面并在那儿提出要求。

Related data and serialization

有趣的插件!

答案 1 :(得分:0)

ansible-playbook的详细程度执行-vvv会显示invocation参数,即使使用默认的标准输出回调也是如此。