Small modification, shows a proof of concept on how we can enable other
top-level command line flags by interacting with Rake (they could make this
easier, to be honest).
Two pending tests for a `--trace` option and a `--format` option, I'm not
fixed on these names, but the notion stands.
Support filtering of roles
# config/deploy/stage.rb
server 'example1.com', roles: %w{web app db}, active: :true
server 'example2.com', roles: %w{web app db}
on :app, filter: :active do
# do things on just example1.com
end
# config/deploy/stage.rb
server 'example1.com', roles: %w{web app db}, active: :true
server 'example2.com', roles: %w{web app db}
on :app, filter: { active: true } do
# do things on just example1.com
end
This patch makes it possible to do something like:
server 'example.com', some_property: true
on(:all, filter: :some_property) do |h|
# ...
end
This is the shorthand syntax which checks the host properties for anything
truthy matching the key name given. Symbols and strings are supported here.
If a more complex match should be made, then a continuation can be given in
the place of the smybol:
server 'example.com', some_property: true
on(:all, filter: lambda { |h| h.properties.some_property }) do |h|
# ...
end
The keys `filter` and `select` are aliases of one another. Either may be used
interchangably.
An execption is raised if the filter removes all matching servers.
Prior to this commit the "primary" server in each role was considered to be
the first one defined. This commit extends the behaviour of primary selection
to look to see if any of the hosts have the `primary` property set to a truthy
value.
In case that more than one server has a truthy `primary` property the first
one is taken as previously.
In order to set the primary property the extended `server()` syntax (that is
not `role()`) must be used, see b56206e.
This syntax allows servers to be specified long-hand including properties.
The `role(:my_role, %w{example.com, example.org})` is convenient for batch
set-up of servers; but as SSHKit provides arbirtary properties on servers, it
might be handy to set up servers in long hand:
server('example.com', roles: :my_role, my_property: "my_value")
server('example.com', roles: [:my_role, :another], my_property: "my_value")
server('example.com', roles: :my_role, primary: true)
This commit adds the ability to do this.