Vagrant show instance IP address?

1,724 views
Skip to first unread message

Amos S

unread,
Mar 31, 2015, 5:56:30 PM3/31/15
to vagra...@googlegroups.com
Hi,

I use Vagrant mainly with AWS VPC right now. I frequently have to know the Vagrant box's IP address in order to run things like "curl" connecting to it from my laptop.

I'm aware of "vagrant ssh" giving me an interactive shell on the box itself, but I want to be able to communicate with it directly from my laptop.

Right now the only way I found is to lookup the instance in the AWS console (additional tags like "environment=vagrant", username and instance name make it easy to find).

I was wondering whether there is already a way to query this information from Vagrant itself, after all it uses this information heavily in order to ssh into the instance.

What I have in mind is something like perhaps "vagrant status --long".

Any thoughts? Am I missing something?

Thanks.

Alvaro Miranda Aguilera

unread,
Mar 31, 2015, 6:46:28 PM3/31/15
to vagra...@googlegroups.com
perhaps vagrant ssh-config

?
> --
> 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 vagrant-up+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Amos S

unread,
Mar 31, 2015, 6:54:40 PM3/31/15
to vagra...@googlegroups.com
Thanks. At least it contains the IP address.

Alvaro Miranda Aguilera

unread,
Mar 31, 2015, 6:58:52 PM3/31/15
to vagra...@googlegroups.com
It also should have the needed if you want to use scp/sftp directly
using the same .pem

but not sure for AWS..

Amos S

unread,
Mar 31, 2015, 9:18:30 PM3/31/15
to vagra...@googlegroups.com
On Wednesday, 1 April 2015 09:58:52 UTC+11, Alvaro Miranda Aguilera wrote:
It also should have the needed if you want to use scp/sftp directly
using the same .pem

The way I work with this right now (subject to possible later refactoring) is that the Vagrant basebox is already very similar to our non-vagrant EC2 "golden AMI"'s and together with my general .ssh/config file it makes it easy for me to "ssh aws-private-ip-address" and get onto any EC2 instance. I just need the address.

Here is what my .ssh/config look like:

ForwardAgent yes
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/default-key-used-also-by-vagrant.pem

Host 10.*
    User ubuntu
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no

With this config, I can do "ssh ip-address"/"scp ip-address"/"rsync ip-address".

Cheer,

--Amos

Robert Ford

unread,
Apr 7, 2015, 11:47:33 AM4/7/15
to vagra...@googlegroups.com
What I do is just use a vagrant ssh --comand to get the output and pipe to a local file.  In our case we use puppet so the example uses "facter" but you can get the info anyway you want.

vagrant ssh --command "facter --json -p" > instancefacts.json
vagrant ssh --command "facter -p ipaddress" > ipaddress.txt

I can then load the ipaddress.txt or I can load the json and use it to get that data or get the dns name and much, much more. 

If you have ec2tools installed on your instance you could also use something like ec2-describe-instances or the myriad of other ec2 tools to get info about the system if setup properly.

As long as you are not using any "puts" in your vagrant that will mess up the output you can use this technique for just about anything.

I also add:

aws.ssh_host_attribute = :dns_name

to my aws vm provider.  This way the vagrant ssh will work from an internal ec2 network (I launch ec2 vagrant images from an existing ec2 instance) or from an external network if you launch it from a local server or desktop.

Thanks,

robo
Reply all
Reply to author
Forward
0 new messages