An introduction to Rex automation and orchestration. Presentation given at FLOSS UK DevOps York 2015. Get a general overview of Rex and find out why I like to use it.
2. Contents
● Introduction
– Why this talk
– What is Rex
● General features
● Why I use Rex
● Installation
● General examples
● How I use Rex
3. Why this talk?
● Rex not as well known as other orchestration
tools
● I'm a recent convert - spread the word!
4. What is Rex?
● "Remote Execution"
● Easily run batched commands remotely
● Similar in concept to Ansible (push not pull)
● Start with Rexfile (Makefile)
● A Rexfile contains tasks
5. General features
● Group by server type
● Very flexible scripting (Perl)
– Minimal Perl knowledge required
– Strength and a weakness?
● Many modules, or add your own (to core?)
● Augeas interface
● Transactions and rollback
● Store config in database
6. Why I use Rex
● Community not commercial
● Very helpful maintainers and mailing list
● Fast merges for PRs
● Very active project
● Flexible
8. Example Rexfile
set connection => "OpenSSH";
user "root";
private_key "~/.ssh/id_rsa";
public_key "~/.ssh/id_rsa.pub";
key_auth;
task "say_uptime", sub {
say run "uptime"
};
23. Transactions
task "do-something", "server01", sub {
on_rollback {
rmdir "/tmp/mydata";
};
transaction {
mkdir "/tmp/mydata";
upload "files/myapp.tar.gz", "/tmp/mydata";
run "cd /tmp/mydata; tar xzf myapp.tar.gz";
if ($? != 0) {
die("Error extracting myapp.tar.gz");
}
};
};
24. How I use Rex
● Central configuration database
● Extract server groups from database
● Set of "base" tasks
● Other tasks depending on server type
$ rex -H newserver web_server
25. How I use Rex
include qw/
Common::SSH
Common::Web
/;
task "base", group => "base", sub {
Common::SSH::clampdown();
};
task "install_gads", group => "gads_servers", sub {
base();
Common::Web::install_app(
base_domain => 'ctrlo.com',
cert_domain => 'gads.ctrlo.com',
);
};
26. Config from database
use JSON;
my $groups = json_decode(
`configdb.pl --type server --action summary`
);
foreach my $group (@$groups) {
my $type = $group->{type};
my @servers = @{$group->{servers}};
group $type => @servers;
}
task "setup_apache", group => "web", sub {
...
};