简体   繁体   English

Ansible 使用命令行传递 ssh 用户名和密码无效

[英]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:注意我试过:

  1. Removing in hosts.ini file在 hosts.ini 文件中删除
    [defaults]
    host_key_checking = false
  1. I also tried by changing 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.

相关问题 如何在命令行参数中接受密码以使用python登录ssh - How to accept password in command line argument for ssh login using python Ansible - 禁用 ssh 密码验证 - Ansible - disable ssh password authentication 使用getopts传递给函数时,命令行参数不起作用 - Command line argument not working when passing to a function while using getopts ansible-playbook 从命令行传递的额外变量 - ansible-playbook extra vars passing from command line SSH隧道:第一跳用户名/密码,第二跳使用SSH密钥 - SSH tunneling: first hop username/password, second hop using SSH key bash脚本中的SSH仍然会提示输入密码,而命令行中的ssh使用密钥进行身份验证时 - SSH in bash script still prompts password while ssh on command-line authenticates with key 在脚本中传递哈希的SSH密码 - Passing hashed ssh password in a script 使用'expect'命令将密码远程传递给SSH运行脚本 - Using 'expect' command to pass password to SSH running script remotely EXISTS =`ssh xyz'egrep“$ username”/ etc / passwd | cut -d':' - f1'`命令无法正常工作 - EXISTS=`ssh xyz 'egrep “$username” /etc/passwd | cut -d':' -f1'` command is not working properly 如何从用户名和密码提供的命令行运行 Interactive broker TWS linux 版本 10.12.2j? - How to run Interactive broker TWS linux version 10.12.2j from command line supplied by username and password?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM