Open amrnt opened 10 years ago
I currently use something like this in a config/deploy/vagrant.rb
to deploy to an EC2 instance I've brought up with vagrant (I have some slightly more complicated configs for multi-machine apps).
require File.expand_path('../../../lib/cockpit/version', __FILE__)
vagrant_status = `sudo -u \`whoami\` vagrant status 2>&1`
if vagrant_status.match(/cockpit-web-precise64-#{Cockpit::BOX_VERSION}\s*running/)
ssh_config = `sudo -u \`whoami\` vagrant ssh-config 2>&1`
raise ssh_config unless ssh_config.match(/^Host/)
vagrant_ip = ssh_config.match(/HostName\s+([a-zA-Z0-9\.]*)$/m)[1]
vagrant_port = ssh_config.match(/Port\s+(\d*)$/m)[1]
vagrant_user = ssh_config.match(/User\s+([a-zA-Z0-9_]*)$/m)[1]
server "#{vagrant_ip}:#{vagrant_port}", user: vagrant_user, roles: %w{web app}
end
It's dirty, I haven't had a chance to clean it up much yet, but it gets the job done. The use of sudo
is to execute vagrant within a clean shell, because vagrant will complain about bundler if it's executed from within a rake/capistrano process (I assume because that's all already running within a bundled environment).
Just for some context: I then take the provisioned (with vagrant) and deployed (with capistrano) instance and create an AMI, then use that AMI to spin up instances in my auto-scaling groups and/or load balancers. My staging, production, etc. capistrano stage configs then build their list of servers by querying all the instances running in those groups (or our load balancers in some cases, for apps that aren't auto-scaled).
Edit: You'll want to pass the machine name to the vagrant ssh-config MACHINE_NAME
command if you're spinning up multiple machines. I'm not doing it in the example above because it's the only configured machine for that app, so vagrant ssh-config
just returns it's config.
@amrnt What I'm considering adding is a JSON file in .vagrant
that lists information about provisioned machines, e.g.:
{
"hosts":
[
{
"provisioned": true,
"public_hostname": "foo.com",
"internal_hostname": "foo.internal",
"elastic_ip" : "123",
"tags" : {}
}
]
}
Would this meet your needs?
Hi @rtyler,
What became of this idea? I would sure like to be able to grab the public and private IPs as well.
+1
I'm trying to deploy my application on a machine and the database on another machine.
I set up both machines with config like this:
How can I tell Capistrano the IP address of the machines?
OR, can I setup both machines through an amazon machine and assign private IPs to setup the other machines without public IPs?