Inventory file is not updated to use private key or passwordless connection between Ansible controller and managed node is not setup correctly

hi all. I am facing the issue. module 3 and lab: distribute ssh keys. (Last question)
i have generated key using ssh-keygen command and also copied it on remote server(web1) using ssh-copy-id command. bwlow is the inventory file.

thor@ansible-controller ~$ cat /home/thor/playbooks/inventory
web1 ansible_host=172.20.1.100 ansible_ssh_private_key_file=home/thor/.ssh/ansible

i am using default ansible.cfg .adding invneory line code below.

thor@ansible-controller ~$ cat /etc/ansible/ansible.cfg
# config file for ansible -- https://ansible.com/
# ===============================================

# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first

[defaults]

# some basic default values...

inventory      = /home/thor/playbooks/inventory
#library        = /usr/share/my_modules/
#module_utils   = /usr/share/my_module_utils/
#remote_tmp     = ~/.ansible/tmp
#local_tmp      = ~/.ansible/tmp
#plugin_filters_cfg = /etc/ansible/plugin_filters.yml
#forks          = 5
#poll_interval  = 15
#sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = True
#transport      = smart
#remote_port    = 22
#module_lang    = C
#module_set_locale = False

# plays will gather facts by default, which contain information about
# the remote system.
#
# smart - gather by default, but don't regather if already gathered
# implicit - gather by default, turn off with gather_facts: False
# explicit - do not gather by default, must say gather_facts: True
#gathering = implicit

after doing following changes , i ran the command .
thor@ansible-controller ~$ ansible -m ping -i inventory web1
[WARNING]: Unable to parse /home/thor/inventory as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not
match 'all'

 [WARNING]: Could not match supplied host pattern, ignoring: web1

i have tried checking further using verbose output

thor@ansible-controller ~$ ansible -m ping all -vvv
ansible 2.7.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/thor/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Jun 20 2019, 20:27:34) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
/home/thor/playbooks/inventory did not meet host_list requirements, check plugin documentation if this is unexpected
/home/thor/playbooks/inventory did not meet script requirements, check plugin documentation if this is unexpected
Parsed /home/thor/playbooks/inventory inventory source with ini plugin
META: ran handlers
<172.20.1.100> ESTABLISH SSH CONNECTION FOR USER: None
<172.20.1.100> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="home/thor/.ssh/ansible"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/thor/.ansible/cp/97f114f412 172.20.1.100 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<172.20.1.100> (255, '', 'no such identity: home/thor/.ssh/ansible: No such file or directory\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n')
web1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: no such identity: home/thor/.ssh/ansible: No such file or directory\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
    "unreachable": true
}

please help. Thanks in advance :slight_smile:

Hello, @bhvk49

You have not define properly ansible_ssh_private_key_file=/home/ instead of ansible_ssh_private_key_file=home/…
By default it’s finding in the current working directory, which is not available. Hope it will help you.

1 Like

You need to include ansible_user=ansible along with ansible_ssh_private_key_file=~/.ssh/ansible in your inventory file

Refer below to understand inventory file

Hello, @swatip
Please don’t provide full solution.

Hello All, Even I am facing this issue. I had setup the inventory file with the below details but still it says the same error?

I am also facing same issue while i am doing the same step.
image

web1 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).”,
“unreachable”: true
}
Inventory file is not updated to use the private key, or passwordless connection between Ansible controller and managed node is not setup correctly.

@Tej-Singh-Rana please check and let us know if we are missing some thing while doing this question.

vi in the path "playbooks/inventory and align the resources
web1 ansible_host=172.20.1.100 ansible_user=ansible ansible_ssh_private_key_file=~/.ssh/ansible
it works …i figured it out by watching the course on kodekloud again …