[英]Ansible passing ssh username and Password using command line is not working
I need to pass username and password instead of using passwordless ssh keys.我需要传递用户名和密码,而不是使用无密码的 ssh 密钥。
I used below command for that我为此使用了以下命令
ansible-playbook -i hosts.ini main.yml --extra-vars "ansible_sudo_pass=$(ansible_password) ansible_user=$(ansible_user) ansible_ssh_pass=$(ansible_password)"
my inventory file hosts.ini我的清单文件 hosts.ini
[all]
10.1.5.4
[defaults]
host_key_checking = false
[all:vars]
ansible_connection=ssh
timeout=20
Below is the error:以下是错误:
TASK [add_repo : Add repository] ***********************************************
fatal: [10.1.5.4]: FAILED! => {"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host."}
Note I tried:注意我试过:
[defaults]
host_key_checking = false
ansible_ssh_pass=$(ansible_password)
to ansible_password=$(ansible_password)
我还尝试将ansible_ssh_pass=$(ansible_password)
更改为ansible_password=$(ansible_password)
Just posting answer for my question, it may help others in case they stuck with same issue.只是发布我的问题的答案,如果其他人遇到同样的问题,它可能会有所帮助。
I have added below entry in file /etc/ansible/ansible.cfg and it start working.我在文件 /etc/ansible/ansible.cfg 中添加了以下条目,它开始工作。
host_key_checking = False
Even I have added same above settings in hosts.ini file, seems it does not taken effect.即使我在hosts.ini文件中添加了上述相同的设置,似乎也没有生效。
It appears that the problem is not with Ansible but with the connection via SSH Try deleting the key fob folder and reconnecting by看来问题不在于 Ansible,而在于通过 SSH 的连接尝试删除密钥卡文件夹并通过以下方式重新连接
rm -r ~/.ssh
But be careful, it will delete all keys for direct connection without a password in the registered devices.但要小心,它会删除所有已注册设备中无需密码直接连接的密钥。 From then on, on the new SSH connection, at the first option after the password, choose yes.从那时起,在新的 SSH 连接上,在密码后的第一个选项中,选择是。
I think it will be better if you write it in main.yml.我觉得你写在main.yml里会更好。 You can refer to it.你可以参考一下。 https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.