如何解决Ansible 'no_log' 用于调试输出中的特定值,而不是整个模块
我正在为 Ansible 自动化 (EX407) 的 RedHat 认证专家学习,我正在尝试使用 no_log
模块参数。我有一个这样结构的示例剧本;
---
- hosts: webservers
tasks:
- name: Query vCenter
vmware_guest:
hostname: "{{ vcenter['host'] }}"
username: "{{ vcenter['username'] }}"
password: "{{ vcenter['password'] }}"
name: "{{ inventory_hostname }}"
validate_certs: no
delegate_to: localhost
no_log: yes
...
当 no_log
被禁用时,我会得到很多关于我的 VM 的有用调试信息,但是当 no_log
被禁用时,我显然无法保护我的剧本存储数据(在这种情况下,这是vcenter['username']
和 vcenter['password']
值)。启用 no_log
会削弱我的剧本调试输出;
"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result",
我想知道如何仅审查部分调试输出。我知道这是可能的,因为无论我的 vcenter['password']
状态如何,no_log
在它的输出中都受到保护。当 no_log
被禁用时,我在详细输出中看到了这一点;
"invocation": {
"module_args": {
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER","username": "administrator@vsphere.local"
}
}
你有什么想法?
解决方法
所以我深入研究了 VMWare 模块源代码,我发现了 this。
password=dict(type='str',aliases=['pass','pwd'],required=False,no_log=True,fallback=(env_fallback,['VMWARE_PASSWORD'])),
看起来 Playbooks 并未公开此功能。 VMWare 模块本身在 Python 中的特定属性上启用 no_log
。就我而言,这只是 Playbooks 隐藏的另一个功能。我真的希望抑制特定属性是标准的,而不是整个模块,但这就是 Ansible 2.10 的位置。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。