On 1/22/09 4:12 AM, Gerhardus Geldenhuis wrote:
> I have found this very usefull, however I do not understand the
> difference between HOSTS and HOSTFILTER. It would be great if you
> could explain it from another angle
I'll give it another try. Consider this concrete example. Suppose your
script defines three servers, A, B, and C. And it defines a task, "foo",
that (by default) wants to run on A and B, but not C. Like this:
role :app, "A", "B"
role :web, "C"
task :foo, :roles => :app do
run "echo hello"
end
Now, if you do "cap foo", it will run the echo command on both A and B.
If you do "cap HOSTS=C foo", it will run the echo command on C,
regardless of the :roles parameter to the task.
If you do "cap HOSTFILTER=C foo", it will not run the echo command at
all, because the intersection of (A B) and (C) is an empty set. (There
are no hosts in foo's host list that match C.)
If you do "cap HOSTFILTER=A foo", it will run the echo command on only
A, because (A B) intersected with (A) is (A).
Lastly, if you do "cap HOSTFILTER=A,B,C foo", it will run the echo
command on A and B (but not C), because (A B) intersected with (A B C)
is (A B).
To summarize: HOSTS completely overrides the hosts or roles declaration
of the task, and forces everything to run against the specified host(s).
The HOSTFILTER, on the other hand, simply filters the existing hosts
against the given list, choosing only those servers that are already in
the tasks server list.
Hope that's clearer,
Jamis