Alv*_*avo 3 ansible ansible-vault
我想做类似的事情
ansible-playbook myPlaybook.yml -i myHostFile
Run Code Online (Sandbox Code Playgroud)
代替
ansible-playbook myPlaybook.yml -i myHostFile --ask-vault-pass
Run Code Online (Sandbox Code Playgroud)
你的要求不明确。根据我的评论,这个答案是一个具体示例,说明如何使用vault-keyring-client.pyansible 社区 contribs 提供的脚本来保护 gnome linux 会话密钥环内的保管库密码(希望它能给您一些关于如何在特定情况下解决问题的想法) 。
pip install keyring
Run Code Online (Sandbox Code Playgroud)
cd $HOME/bin
curl -o vault-keyring-client https://raw.githubusercontent.com/ansible-community/contrib-scripts/main/vault/vault-keyring-client.py
chmod 0700 vault-keyring-client
Run Code Online (Sandbox Code Playgroud)
login启动后您可以看到浏览密钥环的密码条目seahorse(即“密码和密钥”)。
vault-keyring-client --set --vault-id yourid1
vault-keyring-client --set --vault-id yourid2
Run Code Online (Sandbox Code Playgroud)
.bashrc(或您使用的任何 shell...)
export ANSIBLE_VAULT_IDENTITY_LIST=yourid1@$HOME/bin/vault-keyring-client,yourid2@$HOME/bin/vault-keyring-client
export ANSIBLE_VAULT_ENCRYPT_IDENTITY=yourid1
Run Code Online (Sandbox Code Playgroud)
# using the default encrypt vault-id
ansible-vault encrypt somefile
ansible-vault encrypt_string "somestring"
# using an other vault-id than default
ansible-vault encrypt --encrypt-vault-id yourid2 somefile
ansible-vault encrypt_string --encrypt-vault-id yourid2 "somestring"
Run Code Online (Sandbox Code Playgroud)
ansible-playbook -i your_inventory your_playbook
ansible-playbook -i your inventory somehost -m debug -a "msg={{ some_encrypted_var }}"
Run Code Online (Sandbox Code Playgroud)