我使用ansible保险库来加密密码,但是当我使用调试模式时,它将密码显示为纯文本 . 考虑下面的代码
生成ansible-vault加密密码
ansible-vault encrypt_string 'abc123' --name ansible_ssh_pass > inventory/group_vars/all.yml
test.yml
- name: Vault test
hosts: group_1
tasks:
- name: Read Json
set_fact:
version_file: "{{ lookup('template','template/test.j2') | to_json }}"
run_once: true
库存/主机
[group_1]
xxx.xxx.com ansible_host=xx.xx.xx.xx ansible_user=root
xxx.xxx.com ansible_host=xx.xx.xx.xx ansible_user=root
模板/ test.j2
{ "host" : "xxx.xxx.com",
"username" : "root",
"password" : "{{ hostvars[groups['group_1'][0]]['ansible_ssh_pass'] }}" }
Playbook执行
ansible-playbook -i inventory/hosts test.yml --ask-vault-pass -vvv
产量
TASK [Read Json] ******************************************************************************************************************************************
task path: /test/test.yml:5
ok: [xxx.xxx.com] => {
"ansible_facts": {
"version_file": "\"{ \\\"host\\\" : \\\"xxx.xxx.com\\\",\\n \\\"username\\\" : \\\"root\\\",\\n \\\"password\\\" : \\\"abc123\\n\\\" }\\n\""
},
"changed": false,
"failed": false
}
有什么方法可以避免这种情况吗?
2 回答
AFIK ansible vault encript密码,虽然如果你使用详细选项可以看到...为此你必须添加到你的剧本选项:
他们说:看看这个link:
我不相信Ansible会跟踪来自保险库的内容 . 要保护数据,您可以使用
no_log: true
要保护数据,您可以使用
no_log: true