geerlingguy / ansible-for-devops

Ansible for DevOps examples.
https://www.ansiblefordevops.com
MIT License
8.47k stars 3.47k forks source link

Unreachable vagrant boxes #418

Open lazytowntechie opened 3 years ago

lazytowntechie commented 3 years ago

Currently having issue with running my ansible playbook after running vagrant up. image

Here's my Vagrant file:

# -*- 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/centos8"
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider :virtualbox do |v|
    v.memory = 512
    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

Here's my hosts.ini file:

# Application servers
[app]
192.168.60.4
192.168.60.5

# Database server
[db]
192.168.60.6:2201

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

# Variables that will be applied to all servers
[multi:vars]
ansible_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
Divi6 commented 3 years ago

Same here! I'm also having this issue there is only one slight difference in the hosts.ini file, as I do not declare the port in the [db] machine.

nitinsinghit commented 3 years ago

I am also having the same issue? Can someone please help?

nitinsinghit commented 3 years ago

Same here! I'm also having this issue there is only one slight difference in the hosts.ini file, as I do not declare the port in the [db] machine.

Did you figure this out?

nitinsinghit commented 3 years ago

Currently having issue with running my ansible playbook after running vagrant up. image

Here's my Vagrant file:

# -*- 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/centos8"
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider :virtualbox do |v|
    v.memory = 512
    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

Here's my hosts.ini file:

# Application servers
[app]
192.168.60.4
192.168.60.5

# Database server
[db]
192.168.60.6:2201

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

# Variables that will be applied to all servers
[multi:vars]
ansible_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key

Were you able to figure this out?

lazytowntechie commented 3 years ago

No unfortunately, it seems to work randomly when you run vagrant up as if it's on a different ssh port every-time however I did this on my work laptop so I'll need to try it on my personal laptop and see if I get different results

kenhia commented 3 years ago

Can you vagrant ssh to any of the boxes? Does the file ~/.vagrant.d/insecure_private_key exist and does it have an RSA private key?

nitinsinghit commented 3 years ago

Can you vagrant ssh to any of the boxes? Does the file ~/.vagrant.d/insecure_private_key exist and does it have an RSA private key?

yes and yes

meleschi commented 2 years ago

The private network / IPs defined in the Vagrantfile may have static routes in your work laptop that take precedence over the 'local private' network defined there.

I'd start by checking any routes on the computer you're running vagrant on.

You might try changing the network block as well (maybe 10.0.0.*?). If you do change the network block in the Vagrantfile, remember to change the IPs in your hosts.ini file as well.

mcheck commented 2 years ago

Thanks @meleschi Must have that IP subnet in my routes somewhere. Odd thought that so many of us do...

I changed to 192.168.99.x and got this:

The IP address configured for the host-only network is not within the
allowed ranges. Please update the address used to be within the allowed
ranges and run the command again.

  Address: 192.168.99.4
  Ranges: 192.168.56.0/21

Valid ranges can be modified in the /etc/vbox/networks.conf file. For
more information including valid format see:

  https://www.virtualbox.org/manual/ch06.html#network_hostonly

which is a subnet range that allows addresses from 192.168.56.1 - 192.168.63.254

I changed the addresses to 192.168.57.x and it worked.

DonPwrShellHunt commented 2 years ago

I am using the VMware_desktop provisioner rather than VirtualBox, so this comment may not be applicable to those of you using VirtualBox.

In my Vagrantfile, when I use the syntax for a private_network as> app.vm.network :private_network, ip: "192.168.60.x" each of my hosts is in a separate vmnet, and oddly I could connect to the first host, but not the other 2. Manually changing the vmnet to match the first host fixed my connectivity issues.

Reviewing the Vagrant docs, I noticed the syntax was listed as> app.vm.network "private_network", ip: "192.168.60.x" Using this syntax, Vagrant provisioned all my hosts on the same vmnet - everything worked!

After looking at the Vagrant docs again (i'm new to vagrant), I did see the :private_network syntax used for Docker, so I'm not sure what the difference really is yet.

g33kdad commented 2 years ago

This is not working at all for me. I am on my personal laptop running Fedora Silverblue 36. I am getting this result: (please excuse the long paste:

[mmc@fedora adhocCommands]$ ansible multi -a "hostname"
The authenticity of host '192.168.60.4 (192.168.60.4)' can't be established.
ED25519 key fingerprint is SHA256:QUsnXefOSFqgDFGcDE3iMAW82LNxeR4jfqtRkHcDsZM.
This key is not known by any other names
The authenticity of host '192.168.60.5 (192.168.60.5)' can't be established.
ED25519 key fingerprint is SHA256:QUsnXefOSFqgDFGcDE3iMAW82LNxeR4jfqtRkHcDsZM.
This key is not known by any other names
The authenticity of host '192.168.60.6 (192.168.60.6)' can't be established.
ED25519 key fingerprint is SHA256:QUsnXefOSFqgDFGcDE3iMAW82LNxeR4jfqtRkHcDsZM.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Please type 'yes', 'no' or the fingerprint: yes
Please type 'yes', 'no' or the fingerprint: yes
Please type 'yes', 'no' or the fingerprint: yes
192.168.60.5 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Warning: Permanently added '192.168.60.5' (ED25519) to the list of known hosts.\r\nvagrant@192.168.60.5: Permission denied (publickey,password).",
    "unreachable": true
}

Please type 'yes', 'no' or the fingerprint: yes
Please type 'yes', 'no' or the fingerprint: yes
Please type 'yes', 'no' or the fingerprint: yes

has anyone figured this out????

g33kdad commented 2 years ago

Can you vagrant ssh to any of the boxes? Does the file ~/.vagrant.d/insecure_private_key exist and does it have an RSA private key?

yes and yes

Did you find an answer to this? I am having the same issue, i think....

g33kdad commented 2 years ago

*SOLVED**

When I used the files from the github repository and not the text from the book, it worked. It would seem the version of the book I have is behind... i'll have to look into that

Intertranslations commented 1 month ago

two years later and the problem persi. I have used the Vagrantfile from the book that I purchased a few days go, the file from the book-git and the result is the same

192.168.56.4 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: vagrant@192.168.56.4: Permission denied (publickey,password).", "unreachable": true }

I can connect via vagrant ssh to the server. Manually trying to connect via ssh vagrant@192.168.56.4 asks me for the vagrant password that I don't think is set for the user.

Anyone has solved this?

@geerlingguy any thoughts on the issue?