Aha, AND'ing roles. I have an example of that. There's not a pretty DSL for
it but it can be done.
I'll use one of my examples to illustrate.
I like creating roles, and targeting recipes to them instead of using just
the canned :app and :web.
so my server definitions might look like this, and generally are server
centric rather than role centric.
server "xyz", :app, :haproxy, :sdagent
server "zzz", :db, :sdagent
That being said, I had an issue where some of my stages used haproxy without
sdagent, and my sdagent task would fail if run on that stage.
So I needed a way to still run the haproxy task so haproxy gets installed,
but to NOT run the haproxy specific sdagent task if there was no
intersection between the haproxy and sdagent roles.
The following uses ruby array comparison and an outside .any? to determine
if the block should run.
after "sdagent:setup", "haproxy:setup_sdagent"
desc "setup haproxy sd-agent plugin"
task :setup_sdagent, :roles => :haproxy do
# block executing this task if :sdagent isn't present on any :haproxy
servers.
if (find_servers(:roles => :haproxy).map{|d| d.host} &&
find_servers(:roles => :sdagent).map{|d| d.host}).any?
sudo "sed -i 's/^.*haproxy_url.*$/haproxy_url =
http:\\/\\/127.0.0.1:#{haproxy_stats_listen_port}/g' #{sdagent_config_file}"
sudo %Q{sed -i "s/^.*haproxy_svname.*$/haproxy_svname = `hostname
-s`/g" #{sdagent_config_file}}
run "cd #{sdagent_bin} && #{sudo} ./plugins.py -v
#{haproxy_sdagent_plugin_id}"
end
end
On Thu, Oct 6, 2011 at 1:48 PM, Matt L <[email protected]> wrote:
> I wrote a lovely missive about what I was doing by accidentally mailed
> it directly to Lee. Dang it.
>
> I actually do not want to run it serially, but functionally it doesn't
> really matter if I do for this task. It would be nice to know how to
> do this.
>
> It all really boils down to the problem of being able to work with
> role inclusion and exclusion. That is, I want to be able to write
> tasks where I can string AND logic to roles so that only hosts that
> are members of the roles that I specify together are referenced in the
> cap task. I really wish there was a way in cap that did this easily,
> but all logic is effectively OR based so specifying roles means a host
> only needs to be in one of the roles specified to be included in the
> cap invocation. Does this make sense?
>
> This is essentially what I am mucking with and why I even have to do
> the run of all tasks in a namespace in the first place.
>
> Anyway, I have a workaround for all of this and while it isn't
> elegant, it works... serially.
>
> On Oct 4, 1:08 am, Lee Hambley <[email protected]> wrote:
> > My code, although it's /for/ multistage represents the only way I could
> > reliably define tasks programmatically, maybe it helps him.
> >
> > He was creating the right tasks nut he was trying to create a 'meta' task
> >
> > > that serially called the methods of each configured stage. So he can
> call
> > > them individually and optionally together.
> >
> > Could be, It was late, and I definately didn't read it clearly enough, OP
> > will hopefully come back.
> >
> > - Lee
> >
> > On 4 October 2011 03:39, Donovan Bray <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > I immediately thought multi stage is what he was trying to do; but
> that's
> > > really not the only thing he was trying to do.
> >
> > > He was creating the right tasks nut he was trying to create a 'meta'
> task
> > > that serially called the methods of each configured stage. So he can
> call
> > > them individually and optionally together.
> >
> > > If I read his code correctly
> >
> > > On Oct 3, 2011, at 1:45 PM, Lee Hambley <[email protected]> wrote:
> >
> > > You might want to look here, it's really not pretty – but it worked as
> a
> > > proof of concept, there has to be a nicer way though:
> >
> > > <
> https://github.com/leehambley/capistrano-yaml-multistage/blob/master/...>
> > >https://github.com/leehambley/capistrano-yaml-multistage/blob/master/.
> ..
> >
> > > Long story short, that's a Rails 2.x app where I wanted to be able to
> do
> > > multistage without requiring multi-stage.
> >
> > > - Lee
> >
> > > --
> > > * You received this message because you are subscribed to the Google
> Groups
> > > "Capistrano" group.
> > > * To post to this group, send email to <[email protected]>
> > > [email protected]
> > > * To unsubscribe from this group, send email to
> > > [email protected] For more options, visit this
> group
> > > at <http://groups.google.com/group/capistrano?hl=en>
> > >http://groups.google.com/group/capistrano?hl=en
> >
> > > --
> > > * You received this message because you are subscribed to the Google
> Groups
> > > "Capistrano" group.
> > > * To post to this group, send email to [email protected]
> > > * To unsubscribe from this group, send email to
> > > [email protected] For more options, visit this
> group
> > > athttp://groups.google.com/group/capistrano?hl=en
>
> --
> * You received this message because you are subscribed to the Google Groups
> "Capistrano" group.
> * To post to this group, send email to [email protected]
> * To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> at http://groups.google.com/group/capistrano?hl=en
>
--
* You received this message because you are subscribed to the Google Groups
"Capistrano" group.
* To post to this group, send email to [email protected]
* To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/capistrano?hl=en