gpt4 book ai didi

ansible - 无法在 Ansible 中检索保管库 secret

转载 作者:行者123 更新时间:2023-12-02 14:28:45 34 4
gpt4 key购买 nike

我无法使用 VMware 动态 list 文件从保管库读取 secret 。

库存:
https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.ini (在我的 Ansible 目录结构中将其用作 vmware.yml)
https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.py

更新了动态 list 脚本中的几行( vmware_inventory.py -#L213) 读取变量 -

'ini_path': os.path.join(os.path.dirname(__file__), '../group_vars/vmware/vmware.yml'),

Ansible 目录结构:

ansible/
inventory/
vmware_inventory.py
group_vars/
all_vars.yml
vmware/
vmware.yml
vault.yml
roles/

我可以使用 - ansible all -i vmware_inventory.py -m ping ping 所有主机

试验A:
使用 ansible-vault encrypt_string password123 --name 'password' --ask-vault-pass 加密密码值。使用加密密码更新 vmware.yml。

cat vmware.yml

server: vcsa.lab
port: 443
username: devuser
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
62616231653730653366633966626531383362323165643034336533356165626166313466396462
3866363332663963366231636230646465363530666366320a346539343366663135353639646234
65363163386136636662356534343430663133313865333731336230373437663230356361373363
3434633132343731370a393139383464306432626638633837333030623539653462343230373562
6433
validate_certs: False

错误:

vmware_inventory.py) had an execution error: Unable to connect to ESXi server due to (vim.fault.InvalidLogin) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], msg = 'Cannot complete login due to an incorrect user name or password.', faultCause = , faultMessage = (vmodl.LocalizableMessage) [] }

试验 B:按照此 link
创建 ansibleVault 文件 (ansible-vault create../group_vars/vmware/vault) 并添加为纯文本并读取 vmware.yml 中的值

cat vmware.yml

server: vcsa.lab
port: 443
username: dev
password: "{{ vault_password}}"
validate_certs: False

仍然失败并出现相同的错误

Cannot complete login due to an incorrect user name or password.

但我可以使用纯文本运行相同的命令,而无需使用保管库加密密码。

环境:

 ansible 2.7.0
python version = 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]

谁能帮忙找出哪里出了问题?非常感谢您的帮助!

最佳答案

您是否尝试过调试已加密的值。

下面的代码可以用来调试。

    ansible-vault encrypt_string password123 --name 'password'
New Vault Password: test
Confirm New Vault Password: test
--> Copy the generated string to the play as below
---
- name: test
hosts: localhost
vars:
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
35366238333361633133643238666132353564393838306662316139663037666664316461366437
6434386663373838303766643034653832636363313237300a356533396138643531353434386564
66643239346365656631646335613764366136643137666533393031346238633363373662623964
3330396530633331640a626430666335303439653330646565616131376630373932653264386363
3239
tasks:
- name: debug password
debug:
msg: "{{ password }}"

---执行播放

ansible-playbook test2.yml --vault-id password@prompt
Vault password (password): test

关于ansible - 无法在 Ansible 中检索保管库 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54031270/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com