Obtain vagrant-aws instance ID

464 views
Skip to first unread message

Robert Fynes

unread,
Jun 14, 2013, 7:30:12 AM6/14/13
to vagra...@googlegroups.com
Hi,

Is it possible to get the EC2 instance ID of an instance launched using the vagrant-aws plugin, and if so, how?

Thanks,
-Rob

Mike

unread,
Jun 14, 2013, 7:33:16 AM6/14/13
to vagra...@googlegroups.com
From inside or outside?
--
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/groups/opt_out.
 
 

Robert Fynes

unread,
Jun 14, 2013, 7:36:48 AM6/14/13
to vagra...@googlegroups.com
From outside.

Robert Fynes

unread,
Jun 14, 2013, 7:49:17 AM6/14/13
to vagra...@googlegroups.com
Actually, I'm trying to get the public DNS name of the launched instance, but I think I'd like to get the instance ID too.
I'd actually like to get as much information as possible about the instance, but if I have the instance ID, I guess I can use the ec2 api to get whatever I want.

Maybe I should be using Chefs knife ec2 tool instead of Vagrant. My understanding is that Vagrant provides the kind of abstraction so that you don't have to concern yourself with the instance details.
Still, I'd like to use Vagrant.

Mike

unread,
Jun 14, 2013, 7:52:26 AM6/14/13
to vagra...@googlegroups.com

Robert Fynes

unread,
Jun 14, 2013, 8:29:14 AM6/14/13
to vagra...@googlegroups.com
I got this to work:

rfynes@rfynes-laptop$ vagrant ssh --command 'curl -s http://169.254.169.254/latest/meta-data/instance-id'
i-9a91e7d7

...this is the list of metadata that you can pull:

rfynes@rfynes-laptop$ vagrant ssh --command 'curl -s http://169.254.169.254/latest/meta-data/'
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
kernel-id
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups

...and user-data is possible too. 
It's probably not ideal, though (e.g. windows). I think I'd still prefer to pull the id from vagrant, if possible, and then use ec2 tools to get whatever I want.

I'll take a closer look at the source that you referred to, thanks!


Torben Knerr

unread,
Jun 14, 2013, 12:27:52 PM6/14/13
to vagra...@googlegroups.com
You can use the vagrant-awsinfo plugin to get the instance id from the outside:


Robert Fynes

unread,
Jun 14, 2013, 12:39:46 PM6/14/13
to vagra...@googlegroups.com
Perfect, thanks.

Robert Fynes

unread,
Jul 16, 2013, 11:02:10 AM7/16/13
to vagra...@googlegroups.com
For what it's worth, I've discovered that after running 'vagrant up', the automatically generated .vagrant directory (in the root) contains a file .vagrant/machines/default/aws/id (or similar).

This file contains the EC2 instance ID of the launched instance (and nothing else - no line-break).


On Friday, 14 June 2013 12:30:12 UTC+1, Robert Fynes wrote:

Torben Knerr

unread,
Jul 16, 2013, 11:36:52 AM7/16/13
to vagra...@googlegroups.com

I believe 'vagrant ssh-config' should do as well and does not require an additional plugin to be installed.

Have heard of it but not tried it yet...

--
Reply all
Reply to author
Forward
0 new messages