Skip to content

Instantly share code, notes, and snippets.

@krimdomu
krimdomu / update_hash.pl
Created November 24, 2010 14:12
update one hash from another, recursive
We couldn’t find that file to show.
@krimdomu
krimdomu / gist:3490661
Created August 27, 2012 17:36
Using Rex Templates
#######################
# Rexfile
#######################
task "test", sub {
my @arr = ("one", "two", "three");
my %hash = (
name => "foo",
@krimdomu
krimdomu / gist:3707632
Created September 12, 2012 15:54
Rex and multiple files
# Rexfile
group "webservers" => "srv1", "srv2";
group "database" => "db1", "db2";
require Webservers;
require Databases;
###
# File: lib/Webservers.pm
@krimdomu
krimdomu / gist:3707750
Created September 12, 2012 16:09
use perl arrays for group concatenation
my @group1 = qw/host1 host2 host3/;
my @group2 = qw/srv1 srv2 srv3/;
group one => @group1;
group two => @group2;
group all => @group1, @group2;
task "prepare", group => "all", sub {
};
@krimdomu
krimdomu / gist:3900504
Created October 16, 2012 16:50
Getting Hardware Information with Rex
use Rex::Hardware;
use Data::Dumper;
user "root";
password "f00b4r";
pass_auth;
group myservers => "server1", "server2", "server3";
task "get-info", group => "myservers", sub {
@krimdomu
krimdomu / test-ssh.pl
Last active December 11, 2015 00:49
Test Script to verify Net::SSH2 installation
#
# Save this file under /tmp/test-ssh.pl, edit the variables and run it with
# perl /tmp/test-ssh.pl
#
use strict;
use warnings;
# ------- PLEASE SET THE VARS -----------
my $HOST = '';
@krimdomu
krimdomu / gist:4547448
Last active December 11, 2015 04:48
Using a jumphost
use Rex -base;
user "foouser";
task "uptime", "your-server", sub {
say run "uptime";
};
before uptime => sub {
my ($server, $server_ref) = @_;
@krimdomu
krimdomu / gist:4549997
Created January 16, 2013 19:25
Prompt for a password
use Term::ReadKey;
user "root";
# get the CLI parameters
my %args = Rex::Args->getopts;
# only ask for a password if the user don't want to list tasks.
if(! exists $args{T}) {
password read_password();
@krimdomu
krimdomu / gist:4555039
Last active December 11, 2015 05:49
Using Amazon to create dev machines
use strict;
use warnings;
use Data::Dumper;
use Rex::Commands::Cloud;
use Rex::Commands::SimpleCheck;
use Rex::Commands::SCM;
use Rex::Commands::Iptables;
my $access_key = "your-access-key";
@krimdomu
krimdomu / gist:5012195
Created February 22, 2013 09:53
get the servers out of a group
group mygroup => "srv01", "web[01..10]";
task "test", sub {
my @servers = get_servers("mygroup");
for my $srv (@servers) {
run_task "foo", on => $srv, params => { param1 => "value1", param2 => "value2" };
}
};
sub get_servers {