Search code examples
sshvagrantansibleansible-inventory

Ansible: Cannot login to local Vagrant server


I have two Vagrant instances running having different IP:

192.168.33.17 [Ansible installed here]

192.168.33.19 [Another server where I am trying to connect]

My Ansible hosts file is in /etc/ansible/hosts and it looks like:

[example]
192.168.33.19:2222

I can easily connect via SSH to the second server with command:

ssh vagrant@192.168.33.19

without password.

But running the Ansible command yields error:

[root@centos72x64 vagrant]# ansible  example -m ping -u vagrant
192.168.33.19 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}

How I can solve this error?


Solution

  • My Ansible hosts file is in /etc/ansible/hosts and it looks like

    [example]
    192.168.33.19:2222
    

    You don't put port number in the Ansible inventory file this way. To learn how to do it, confer the docs.

    But you also mentioned:

    I can easily connect via ssh to the second server with command

    ssh vagrant@192.168.33.19
    

    So you don't use port 2222 at all.