Ansible : "Failed to connect to the host via ssh: error

Hello Rocky Linux Forum.

I am learning Ansible, and so I ask this question very carefully. Please don’t box me :slight_smile:

I have successfully installed Ansible on my system running on Rocky 9.2 via the commands:

sudo dnf install epel-release

Then installed Ansible:

sudo dnf -y install ansible

Then I placed my inventory file in the Ansibles global inventory file in the


But when I run the Ad-Hoc Ansible command:

ansible -i [my_inventory_file] [server_group] -m ping -u <user>

I get the following error:

$ ansible -i hosts.ini example -m ping -u jil | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: jil@ Permission denied (publickey,password).",
    "unreachable": true

If I ssh to the same server using the same user and server IP address:

$ ssh jil@
jil@'s password: 

I can successfully log in to the server.

where am I making a mistake? PLease educate me.

Add --ask-pass parameter to the ansible command line, or generate an SSH key and use that key instead to connect to the host over ssh.

Usernames can also be passed on the command line, if your current user on the ansible host is not jil.

1 Like

Thank you so much @iwalker . It now works

$ sudo ansible -i hosts.ini example -m ping -u jil --ask-pass
SSH password: | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    "changed": false,
    "ping": "pong"

Thank you.

1 Like

I have set up a passwordless (key-based) login for SSH and worked fine too.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.