我已经为 Amazon EC2
创建了一个自动扩展组,并且在使用 packer
创建 AMI 时添加了我的公钥,我可以运行 ansible-playbook 和 ssh主机。
但是当我像这样运行剧本时出现问题
ansible-playbook load.yml
我收到一条消息,要求我写入密码
Enter passphrase for key '/Users/XXX/.ssh/id_rsa':
Enter passphrase for key '/Users/XXX/.ssh/id_rsa':
Enter passphrase for key '/Users/XXX/.ssh/id_rsa':
问题是它不接受我的密码(我确信我输入的密码正确)。
我发现我可以使用 ask-pass
标志发送密码,因此我已将命令更改为 ansible-playbook load.yml --ask-pass
并且我取得了一些进展,但对于其他一些任务,它再次要求输入密码,但它不接受我的密码
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] *************************************************************************************************************
TASK [ec2_instance_facts] ****************************************************************************************************
ok: [localhost]
TASK [add_host] **************************************************************************************************************
changed: [localhost] => (item=xx.xxx.xx.xxx)
changed: [localhost] => (item=yy.yyy.yyy.yyy)
PLAY [instances] *************************************************************************************************************
TASK [Copy gatling.conf] *****************************************************************************************************
ok: [xx.xxx.xx.xxx]
ok: [yy.yyy.yyy.yyy]
Enter passphrase for key '/Users/ccc/.ssh/id_rsa': Enter passphrase for key '/Users/ccc/.ssh/id_rsa':
Enter passphrase for key '/Users/ccc/.ssh/id_rsa':
Enter passphrase for key '/Users/ccc/.ssh/id_rsa':
Enter passphrase for key '/Users/ccc/.ssh/id_rsa':
如果我不使用 ask-pass
标志,即使任务 [Copy gadling.conf]
也无法完成,并提示无法访问主机。通过添加标志,这部分通过了,但我的下一个任务再次要求通过。
我应该如何解决这个问题?我在这里做错了什么?
最佳答案
在ansible中没有存储受密码保护的私钥的选项
为此,我们需要在 ssh-agent 中添加受密码保护的私钥
在后台启动 ssh-agent。
# eval "$(ssh-agent -s)"
将 SSH 私钥添加到 ssh-agent
# ssh-add ~/.ssh/id_rsa
现在尝试运行 ansible-playbook 并 ssh 到主机。
关于ssh - 如何使用受密码保护的 ssh 私钥运行 ansible-playbook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50277495/