Home > Mobile >  Ansible passing ssh username and Password using command line is not working
Ansible passing ssh username and Password using command line is not working

Time:11-10

I need to pass username and password instead of using passwordless ssh keys.

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


    [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
    [defaults]
    host_key_checking = false
  1. I also tried by changing ansible_ssh_pass=$(ansible_password) to ansible_password=$(ansible_password)

CodePudding user response:

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.

 host_key_checking = False

Even I have added same above settings in hosts.ini file, seems it does not taken effect.

CodePudding user response:

I think it will be better if you write it in main.yml. You can refer to it. https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html

CodePudding user response:

It appears that the problem is not with Ansible but with the connection via SSH Try deleting the key fob folder and reconnecting by

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.

  • Related