forward3d/cap-ec2 — pull request #22 by tomconroy (2014-06-09 17:37:38+00:00)
Title: Add `ec2_server` method to automatically add roles

So, capistrano has two ways of adding hosts: the `role` method, and the `server` method. `server` allows you pass an array of roles with the options. However, the way capistrano stores references to hosts, if you call `role` twice with different roles, but the same host, it ignores the second call. So for servers tagged like so:

Role	Stage

web,app	production

web,db	production

Calling `ec2_role` with the same options for the 3 different roles:

```ruby
%w(web app db).each do |role|
ec2_role role, user: 'deploy', ssh_options: { auth_methods: %w(publickey) }
end
```

Results in `defined_roles` returning only `web`. If we change the order of the calls in this case to `app`, then `db`, then `web`, the `defined_roles` returns `app` and `db`, since they're different hosts. But `web` isn't added.

Perhaps this is a bug with capistrano itself, but we can get around it by defining an extra method `ec2_server` that only takes a list of options for connecting, and passes a list of roles automatically from the EC2 'roles' tag. This currently assumes that each role is connectable in the same way (which may not be desirable?), but it fits our use case.