Hello

Assuming the goal is dev and have some sort of playground, I have done this:

https://github.com/kikitux/vagrant-multimachine

its a multi machine setup that configures /etc/hosts to be able to ssh with
hostname and set the same key on vagrant user.

so should work for ansible, runs and ssh as vagrant and sudo for the
commands. Assuming you later will run this in prod where ssh as root should
be no-go . :D


*0* * (master)* $ vagrant status

Current machine states:


node1                     running (virtualbox)

node2                     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`.

*0* * (master)* $ vagrant ssh node1 -c 'ssh node2 id'

Warning: Permanently added 'node2,192.168.10.12' (ECDSA) to the list of
known hosts.

uid=1000(vagrant) gid=1000(vagrant)
groups=1000(vagrant),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),110(sambashare),999(admin)

Connection to 127.0.0.1 closed.

*0* * (master)* $ vagrant ssh node2 -c 'ssh node1 id'

Warning: Permanently added 'node1,192.168.10.11' (ECDSA) to the list of
known hosts.

uid=1000(vagrant) gid=1000(vagrant)
groups=1000(vagrant),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),110(sambashare),999(admin)

Connection to 127.0.0.1 closed.

*0* * (master)* $



Alvaro.


On Thu, Mar 15, 2018 at 8:17 AM, <[email protected]> wrote:

> I'm trying to find a simple and reliable way to create a Vagrantfile that:
>
> 1. Creates 3 guests, one used to run ansible, and 2 or 3 guests for
> ansible to manage.
> 2. Install ssh keys on the guests so that I can use ssh from the ansible
> guest to control the other guests.
> 3. To start with, I'd as soon use the "script" provisioner, and maybe the
> "file" provisioner, to set things up, since I'm only learning ansible.
>
> I'm doing this from a MacOS High Sierra host, and using ubuntu xenial
> guests.  Provider is Virtualbox.
>
> The problem is that by default, Vagrant 2.0.1 wants to generate different
> keys on the fly for each machine; the keys get created into
> .vagrant/GUEST_NAME/virtualbox/private_key.  You can't just copy this
> file using the file provisioner, though, since the private_key file does
> not actually exist when the guest is first created.
>
> To get around this, I've tried creating a key pair with ssh-keygen.  But I
> don't understand which config.ssh configs to set so that Vagrant will use
> my key rather than using a dynamic generated key.  Just setting
> subconfig.ssh.private_key_path doesn't work for me; the dynamic key gets
> installed to the guest, but vagrant uses my key to communicate with it. So
> vagrant up fails since vagrant can't talk to the host.
>
> I've tried to get around this by just adding my key as an additional key,
> by appending my public key to GUEST:/home/vagrant/.ssh/authorized_keys.
> This almost works.  For some reason, I can't get the file provisioner to
> copy my keys/custom_key.pub file to the guests.  I'm copying from
> /vagrant/keys/custom_key.pub using the script provisioner.  But I also use 
> vagrant-vbguest;
> this means that when I provision a new host, /vagrant is not always mounted
> :-(
>
> I can supply my current script, but first, is there a better way to do
> this?  Seems to be a lot harder that it should be.
>
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in
> violation of those guidelines may result in your removal from this mailing
> list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/vagrant-up/c91ec92b-a349-46bf-9adb-91e8dbad4ae2%40googlegroups.com
> <https://groups.google.com/d/msgid/vagrant-up/c91ec92b-a349-46bf-9adb-91e8dbad4ae2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Alvaro

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/CAHqq0eypAdFYXRixWi%2BHAeyC7g1%3D6ugoSb-YGAThOZNnJJOX6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to