Ansible使用命令行传递ssh用户名和密码的方式无法工作

0 人关注

我需要传递用户名和密码,而不是使用无密码的SSH密钥。

我为此使用了以下命令

    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

[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:

  • Removing in hosts.ini file
  •     [defaults]
        host_key_checking = false
    
  • I also tried by changing ansible_ssh_pass=$(ansible_password) to ansible_password=$(ansible_password)
  • 2 个评论
    你应该把 [defaults] host_key_checking = false 添加到 ansible.cfg 文件中,它应该可以工作。
    你能给我看看ansible.cfg文件的内容吗? 我试了一下你上面添加的同样的命令,对我来说很好用
    linux
    ssh
    ansible
    devops
    Vidya
    Vidya
    发布于 2021-11-09
    1 个回答
    Vidya
    Vidya
    发布于 2021-11-10
    已采纳
    0 人赞同