SSH Connection fails. Permission denied. Publickey, keyboard-interactive

413 views
Skip to first unread message

Gene Stanilevskiy

unread,
Dec 5, 2017, 11:54:05 AM12/5/17
to Ansible Project
Hi All,

New to Ansible.  New to the group.

Trying to run some basic commands against my VMware environment and thought I would start with vmware_facts. 

ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible 
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

Ubuntu 16.0.4 

My hosts file looks like this:

[all]

[windows]
TestServ
TestServ1

[vsphere]
host1 ansible_connection
=ssh ansible_user=root ansible_host=10.0.0.1
host2 ansible_user
=root ansible_connection=ssh ansible_host=10.0.0.2

[localhost]
127.0.0.1 ansible_connection=local

I can successfully run the following command 

ansible vsphere -i hosts -m ping --ask-pass -vvv

| SUCCESS => {
   
"changed": false,
   
"failed": false,
   
"invocation": {
       
"module_args": {
           
"data": "pong"
       
}
   
},
   
"ping": "pong"

 After some research, here is the playbook that I came up with.

---
-
  hosts
: vsphere
  connection
: ssh
  gather_facts
: yes

  vars_prompt
:
   
- name: "pwd"
     prompt
: "Type password"
     
private: yes

  tasks
:

   
- name: Gater facts on virtual machines
     vmware_vm_facts
:
       delegate_to
: localhost
       hosts
: vsphere
       username
: root
       password
: "{{pwd}}"
       validate_certs
: false

But I'm getting "permission denied" when I run the playbook:

ansible-playbook -i hosts group_vars/vmware_get_facts.yml

Type password:

PLAY
[vsphere] ****************************************************************************************************************************************

TASK
[Gathering Facts] **************************************************************************************************************************************
fatal
: [host1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,keyboard-interactive).\r\n", "unreachable": true}
fatal
: [host2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,keyboard-interactive).\r\n", "unreachable": true}
        to
retry, use: --limit @/home/administrator/windows/group_vars/vmware_get_facts.retry


PLAY RECAP
*****************************************************************************************************************************************
host1        
: ok=0    changed=0    unreachable=1    failed=0
host2        
: ok=0    changed=0    unreachable=1    failed=0


When I run the command above with '-vvvv' it looks like the key is found:

Host 'host1' is known and matches the RSA host key

So I wonder if I have a syntax error somewhere or the playbook needs to be re-written. 

Thanks in advance for the help.

Gene

Gene Stanilevskiy

unread,
Dec 5, 2017, 4:02:00 PM12/5/17
to Ansible Project
I think I solved my problem.  I re-wrote the playbook to look like this and it now gets vmware_facts as expected.

---
- hosts: localhost
  connection
: local
  user
: root
  become
: no
  gather_facts
: true
  serial
: 1

  vars_prompt
:
 
- name: "user"
    prompt
: "vCenter username"
   
private: no
 
- name: "pw"
    prompt
: "User's password"
   
private: yes


  tasks
:
   
- vmware_vm_facts:
       hostname
: vcenter.test
       username
: "{{user}}"
       password
: "{{pw}}"
       validate_certs
: False
     delegate_to
: localhost
     
register: vmfacts

   
- debug:
       
var: vmfacts.virtual_machines

Hopefully this helps someone too :-)

Gene
Reply all
Reply to author
Forward
0 new messages