使用 ansible-vault 加密 Ansible Playbook .pem 私钥
Encrypting Ansible Playbook .pem private key with ansible-vault
有没有办法用 ansible-vault 加密 --private-key 并使用 Ansible Playbook ansible-playbook 命令(或在 Playbook 中)加密?
我试过了,但没用:
$ ansible-vault create encrypted_ssh_key.pem --vault-password-file vault_password_file
(将我的 SSH 私钥粘贴到其中)
$ ansible-playbook ansible_playbook -i inventory/ec2.py \
-e ansible_ssh_user=ubuntu \
-e ansible_user=ubuntu \
--private-key=encrypted_ssh_key.pem \
--vault-password-file vault_password_file
它总是要求我输入密码,即使我输入了它(来自 vault_password_file 的那个)它也不接受。我可以使用该私钥毫无问题地登录到 EC2 实例。
抱歉,您采取了错误的方法。
您需要为密钥创建密码,而不是使用 Ansible Vault 加密密钥。
openssl rsa -in ssh_key.pem -out encrypted_ssh_key.pem
给它一个密码,并在每次 运行 时提供该密码(或使用一些代理为您缓存密码):
ansible-playbook ansible_playbook -i inventory/ec2.py \
-e ansible_ssh_user=ubuntu \
-e ansible_user=ubuntu \
--private-key=encrypted_ssh_key.pem
有没有办法用 ansible-vault 加密 --private-key 并使用 Ansible Playbook ansible-playbook 命令(或在 Playbook 中)加密?
我试过了,但没用:
$ ansible-vault create encrypted_ssh_key.pem --vault-password-file vault_password_file
(将我的 SSH 私钥粘贴到其中)
$ ansible-playbook ansible_playbook -i inventory/ec2.py \
-e ansible_ssh_user=ubuntu \
-e ansible_user=ubuntu \
--private-key=encrypted_ssh_key.pem \
--vault-password-file vault_password_file
它总是要求我输入密码,即使我输入了它(来自 vault_password_file 的那个)它也不接受。我可以使用该私钥毫无问题地登录到 EC2 实例。
抱歉,您采取了错误的方法。
您需要为密钥创建密码,而不是使用 Ansible Vault 加密密钥。
openssl rsa -in ssh_key.pem -out encrypted_ssh_key.pem
给它一个密码,并在每次 运行 时提供该密码(或使用一些代理为您缓存密码):
ansible-playbook ansible_playbook -i inventory/ec2.py \
-e ansible_ssh_user=ubuntu \
-e ansible_user=ubuntu \
--private-key=encrypted_ssh_key.pem