question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to connect to the host via ssh: vagrant@192.168.60.5: Permission denied (publickey,password).",

See original GitHub issue

OS: MacosX

ansible -m ping all

192.168.60.4 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: vagrant@192.168.60.4: Permission denied (publickey,password).",
    "unreachable": true
}
192.168.60.5 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: vagrant@192.168.60.5: Permission denied (publickey,password).",
    "unreachable": true
}
192.168.60.6 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: vagrant@192.168.60.6: Permission denied (publickey,password).",
    "unreachable": true
}
cat /etc/ansible/hosts
# Lines beginning with a # are comments and are only included for
# illustration. These comments are overkill for most inventory files.

# Application servers
[app]
192.168.60.4
192.168.60.5

# Database server
[db]
192.168.60.6

# Group 'multi' with all servers
[multi:children]
app
db

# Variables that will ve applied to all servers
[multi:vars]
ansible_ssh_user=vagrant
ansbile_ssh_private_key_file=/Users/florin/.vagrant.d/insecure_private_key
ansible_ssh_common_args='-o StrictHostKeyChecking=no'

$ vagrant ssh-config
Host app1
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/florin/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

Host app2
  HostName 127.0.0.1
  User vagrant
  Port 2201
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/florin/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

Host db
  HostName 127.0.0.1
  User vagrant
  Port 2202
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/florin/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
~/three_servers  cat Vagrantfile
# _*_ mode: ruby _*_
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
 # General Vagrant VM configuration
  config.vm.box = "geerlingguy/centos7"
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider :virtualbox do |v|
    v.memory = 256
    v.linked_clone = true
  end

# Application server 1.
  config.vm.define "app1" do |app|
    app.vm.hostname = "orc-app1.test"
    app.vm.network :private_network, ip: "192.168.60.4"
  end

# Application server 2.
  config.vm.define "app2" do |app|
    app.vm.hostname = "orc-app2.test"
    app.vm.network :private_network, ip: "192.168.60.5"
  end

# Database server.
  config.vm.define "db" do |db|
     db.vm.hostname = "orc-db.test"
     db.vm.network :private_network, ip: "192.168.60.6"
  end
end

vagrant status
Current machine states:

app1                      running (virtualbox)
app2                      running (virtualbox)
db                        running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
cwebleycommented, Jul 17, 2022

Went through this issue as well. If you’re like me, you just need to pull down the latest code for this chapter.

If you’re following an old version of the book, or the youtube playlist you’ll want to update your Vagrantfile and inventory file (hosts.ini) to the latest published in this repo.

vagrant destroy your old machines and vagrant up the new ones, then

ansible multi -i hosts.ini -a "hostname"

and you should get the output you’re expecting

0reactions
nitinsinghitcommented, Oct 14, 2021

Was able to make it work, after reading this answer https://stackoverflow.com/a/35969858 It seems that I did not have an ansible.cfg file and this was creating this error.

wget https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg
~/three_servers  pwd
/Users/florin/three_servers
~/three_servers  ls
Vagrantfile  ansible.cfg
 ~/three_servers  ansible -m ping multi

192.168.60.4 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.60.6 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.60.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

I tried ansible.cfg but still same error

[defaults]
inventory = hosts.ini
nocows = True
Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found