Skip to content

Instantly share code, notes, and snippets.

@krimdomu
Created November 8, 2013 09:24
Show Gist options
  • Select an option

  • Save krimdomu/7368520 to your computer and use it in GitHub Desktop.

Select an option

Save krimdomu/7368520 to your computer and use it in GitHub Desktop.
get servers out of a group
group servers => "db", "frontend[01..04]";
task "test", sub {
# this returns the content of the group as is. so the frontend servers
# don't get parsed to frontend01, frontend02, ...
my @servers_raw = Rex::Group->get_group("servers");
print Dumper(\@servers_raw);
# this will parse the frontend[01..04] into 4 servers
# returning a list of Rex::Group::Entry::Server objects
my @servers = map { $_->get_servers } @servers_raw;
print Dumper(\@servers);
# if the objects are "called" in string context, they will just
# return the server name.
for my $server (@servers) {
print ">> $server\n";
}
if($servers[0] eq "db") {
print "The first server is 'db'\n";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment