SlideShare a Scribd company logo
(R)?ex
Deployment & Configuration
Management
Andy Beverley
andy@andybev.com
Contents
● Introduction
– Why this talk
– What is Rex
● General features
● Why I use Rex
● Installation
● General examples
● How I use Rex
Why this talk?
● Rex not as well known as other orchestration
tools
● I'm a recent convert - spread the word!
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
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
Why I use Rex
● Community not commercial
● Very helpful maintainers and mailing list
● Fast merges for PRs
● Very active project
● Flexible
Installation
● Packages available for most distributions
● Or:
– cpan Rex
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"
};
Running a Rexfile
$ rex say_uptime
$ rex -H myhost say_uptime
Updating packages
use Rex::Commands::Pkg;
task "upgrade", sub {
update_package_db;
update_system;
};
● Tasks can be contained in your own common modules
Installing and configuring
task "setup_ntp", sub {
install "ntp";
};
Installing and configuring
task "setup_ntp", sub {
pkg "ntp", ensure => "latest";
service ntp => ensure => "started";
};
Installing and configuring
task "setup_ntp", sub {
pkg "ntp", ensure => "latest";
file "/etc/ntp.conf",
source => "files/etc/ntp.conf";
service ntp => ensure => "started";
};
Installing and configuring
task "setup_ntp", sub {
pkg "ntp", ensure => "latest";
file "/etc/ntp.conf",
source => "files/etc/ntp.conf",
owner => "root",
group => "root",
mode => 644;
service ntp => ensure => "started";
};
Installing and configuring
task "setup_ntp", sub {
pkg "ntp", ensure => "latest";
file "/etc/ntp.conf",
source => "files/etc/ntp.conf",
owner => "root",
group => "root",
mode => 644,
on_change => sub {
service ntp => "restart"
};
service ntp => ensure => "started";
};
File command
file "/etc/hosts",
content => template("templates/etc/hosts.tpl"),
owner => "user",
group => "group",
mode => 700,
on_change => sub { say "Something was changed." };
File command
file "/etc/named.conf",
content => template("templates/etc/named.conf.tpl"),
no_overwrite => TRUE;
File command
file "/etc/motd",
ensure => "absent";
delete_lines_matching
"/var/log/auth.log" => "root";
append_if_no_such_line
"/etc/groups", "mygroup:*:100:myuser1,myuser2";
append_or_amend_line "/etc/groups",
line => "mygroup:*:100:myuser3,myuser4",
regexp => qr{^mygroup};
Server groups
group web_servers =>
"web1", "web2", "web3";
group web_servers => "web[1..3]";
group servers =>
"web[1..3]", "db[01..02]", "mail";
Server groups
task "uptime", group => "web_servers",
sub { say uptime; };
Augeas interface
augeas modify =>
"/files/etc/postfix/main.cf/myhostname"
=> "myhost",
"/files/etc/postfix/main.cf/relayhost"
=> "smtp.isp.com";
Augeas interface
augeas modify =>
"/files/etc/postfix/main.cf/myhostname"
=> "myhost",
"/files/etc/postfix/main.cf/relayhost"
=> "smtp.isp.com",
on_change => sub {
service postfix => "restart";
};
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");
}
};
};
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
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',
);
};
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 {
...
};
Certs from database
use Rex::Commands::File;
use IPC::Run3;
use JSON;
Certs from database
my $certs = decode_json(
`configdb.pl --type cert --server $hostname`
);
foreach my $cert (@$certs) {
if ($cert->{type} eq 'key') {
my $key = $cert->{content};
my $out;
run3 "openssl rsa -passin pass:'$pass'", $key, $out;
file $cert->{filename},
content => $out,
owner => "root",
group => "ssl-cert",
mode => 640,
on_change => sub { ... }; # e.g. restart web server
}
}
www.rexify.org
Andy Beverley
andy@andybev.com

More Related Content

ODP
Dancer's Ecosystem
ODP
Writing webapps with Perl Dancer
ODP
Perl Dancer, FPW 2010
PDF
PerlDancer for Perlers (FOSDEM 2011)
PDF
Perl Dancer for Python programmers
PDF
Dancing Tutorial
KEY
Quality Use Of Plugin
KEY
Keeping it small: Getting to know the Slim micro framework
Dancer's Ecosystem
Writing webapps with Perl Dancer
Perl Dancer, FPW 2010
PerlDancer for Perlers (FOSDEM 2011)
Perl Dancer for Python programmers
Dancing Tutorial
Quality Use Of Plugin
Keeping it small: Getting to know the Slim micro framework

What's hot (20)

PDF
Go初心者がGoでコマンドラインツールの作成に挑戦した話
PDF
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
PDF
How to develop modern web application framework
PPT
Writing Friendly libraries for CodeIgniter
PDF
優しいWAFの作り方
PDF
With a Mighty Hammer
PDF
Keeping it Small: Getting to know the Slim Micro Framework
PDF
Inside Bokete: Web Application with Mojolicious and others
PDF
RESTful web services
PDF
Perl web frameworks
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PDF
Building Cloud Castles
KEY
Mojo as a_client
PPT
Slim RedBeanPHP and Knockout
ODP
Maintaining your own branch of Drupal core
PDF
Developing apps using Perl
PDF
Intro to Rails
PDF
Mojolicious
PDF
PerlでWeb API入門
PPTX
Using WordPress as your application stack
Go初心者がGoでコマンドラインツールの作成に挑戦した話
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
How to develop modern web application framework
Writing Friendly libraries for CodeIgniter
優しいWAFの作り方
With a Mighty Hammer
Keeping it Small: Getting to know the Slim Micro Framework
Inside Bokete: Web Application with Mojolicious and others
RESTful web services
Perl web frameworks
Keeping it small - Getting to know the Slim PHP micro framework
Building Cloud Castles
Mojo as a_client
Slim RedBeanPHP and Knockout
Maintaining your own branch of Drupal core
Developing apps using Perl
Intro to Rails
Mojolicious
PerlでWeb API入門
Using WordPress as your application stack
Ad

Similar to An introduction to Rex - FLOSS UK DevOps York 2015 (20)

PPTX
Learning Puppet basic thing
PDF
Replacing Simple Puppet Modules with Providers
PPTX
linux_admin_course_full_for beginers.pptx
PDF
Install nagios
PDF
Install nagios
PDF
Install nagios
PPT
Intro to linux systems administration
PDF
Puppet Camp Dallas 2014: Replacing Simple Puppet Modules with Providers
PPTX
NagiOs.pptxhjkgfddssddfccgghuikjhgvccvvhjj
PDF
Red Hat Linux Pocket Administrator 1st Edition Richard Petersen
PDF
Automated Deployment and Configuration Engines. Ansible
PDF
Linux cgroups and namespaces
PPSX
Linux: An Unbeaten Empire
PPT
PDF
linux installation.pdf
PDF
Get Started with Linux Management Command line Basic Knowledge
PDF
What we Learned Implementing Puppet at Backstop
PDF
CentOS Linux Server Hardening
PPT
Ch23 system administration
PPTX
Linux Presentation
Learning Puppet basic thing
Replacing Simple Puppet Modules with Providers
linux_admin_course_full_for beginers.pptx
Install nagios
Install nagios
Install nagios
Intro to linux systems administration
Puppet Camp Dallas 2014: Replacing Simple Puppet Modules with Providers
NagiOs.pptxhjkgfddssddfccgghuikjhgvccvvhjj
Red Hat Linux Pocket Administrator 1st Edition Richard Petersen
Automated Deployment and Configuration Engines. Ansible
Linux cgroups and namespaces
Linux: An Unbeaten Empire
linux installation.pdf
Get Started with Linux Management Command line Basic Knowledge
What we Learned Implementing Puppet at Backstop
CentOS Linux Server Hardening
Ch23 system administration
Linux Presentation
Ad

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Cloud computing and distributed systems.
PPTX
sap open course for s4hana steps from ECC to s4
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Cloud computing and distributed systems.
sap open course for s4hana steps from ECC to s4
Teaching material agriculture food technology
KodekX | Application Modernization Development
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The AUB Centre for AI in Media Proposal.docx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf

An introduction to Rex - FLOSS UK DevOps York 2015

  • 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
  • 7. Installation ● Packages available for most distributions ● Or: – cpan Rex
  • 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" };
  • 9. Running a Rexfile $ rex say_uptime $ rex -H myhost say_uptime
  • 10. Updating packages use Rex::Commands::Pkg; task "upgrade", sub { update_package_db; update_system; }; ● Tasks can be contained in your own common modules
  • 11. Installing and configuring task "setup_ntp", sub { install "ntp"; };
  • 12. Installing and configuring task "setup_ntp", sub { pkg "ntp", ensure => "latest"; service ntp => ensure => "started"; };
  • 13. Installing and configuring task "setup_ntp", sub { pkg "ntp", ensure => "latest"; file "/etc/ntp.conf", source => "files/etc/ntp.conf"; service ntp => ensure => "started"; };
  • 14. Installing and configuring task "setup_ntp", sub { pkg "ntp", ensure => "latest"; file "/etc/ntp.conf", source => "files/etc/ntp.conf", owner => "root", group => "root", mode => 644; service ntp => ensure => "started"; };
  • 15. Installing and configuring task "setup_ntp", sub { pkg "ntp", ensure => "latest"; file "/etc/ntp.conf", source => "files/etc/ntp.conf", owner => "root", group => "root", mode => 644, on_change => sub { service ntp => "restart" }; service ntp => ensure => "started"; };
  • 16. File command file "/etc/hosts", content => template("templates/etc/hosts.tpl"), owner => "user", group => "group", mode => 700, on_change => sub { say "Something was changed." };
  • 17. File command file "/etc/named.conf", content => template("templates/etc/named.conf.tpl"), no_overwrite => TRUE;
  • 18. File command file "/etc/motd", ensure => "absent"; delete_lines_matching "/var/log/auth.log" => "root"; append_if_no_such_line "/etc/groups", "mygroup:*:100:myuser1,myuser2"; append_or_amend_line "/etc/groups", line => "mygroup:*:100:myuser3,myuser4", regexp => qr{^mygroup};
  • 19. Server groups group web_servers => "web1", "web2", "web3"; group web_servers => "web[1..3]"; group servers => "web[1..3]", "db[01..02]", "mail";
  • 20. Server groups task "uptime", group => "web_servers", sub { say uptime; };
  • 21. Augeas interface augeas modify => "/files/etc/postfix/main.cf/myhostname" => "myhost", "/files/etc/postfix/main.cf/relayhost" => "smtp.isp.com";
  • 22. Augeas interface augeas modify => "/files/etc/postfix/main.cf/myhostname" => "myhost", "/files/etc/postfix/main.cf/relayhost" => "smtp.isp.com", on_change => sub { service postfix => "restart"; };
  • 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 { ... };
  • 27. Certs from database use Rex::Commands::File; use IPC::Run3; use JSON;
  • 28. Certs from database my $certs = decode_json( `configdb.pl --type cert --server $hostname` ); foreach my $cert (@$certs) { if ($cert->{type} eq 'key') { my $key = $cert->{content}; my $out; run3 "openssl rsa -passin pass:'$pass'", $key, $out; file $cert->{filename}, content => $out, owner => "root", group => "ssl-cert", mode => 640, on_change => sub { ... }; # e.g. restart web server } }