(R)?ex Deployment & Configuration Management

Search

News

2016-09-08

Work with (R)?ex at adjust! Check out their job posting for details, or contact our fellow core developer, FErki.

2016-07-16

(R)?ex 1.4.1 released, fixing many bugs. See the release notes for more details.

2016-03-07

(R)?ex 1.4.0 released, containing lots of goodies. See the release notes for more details.

2015-09-04

(R)?ex 1.3.3 released, fixing a bunch of bugs. See the release notes for more details.

2015-06-22

adjust GmbH is sponsoring the (R)?ex project with a new build server. Thank you for your support!

2015-06-17

(R)?ex 1.3.2 released, fixing issues related to file manipulation when run on BSDs. See the release notes for more details.

2015-06-08

(R)?ex 1.3.1 released, fixing Rex::Commands::DB related tests.

2015-05-27

Read the second part of "Rex in practice" series about Test-driven infrastructure.

2015-05-09

repositor.io 1.1.0 released. repositor.io is a repository management tool for apt, yum, yast and docker. This is a bugfix release with fixes for ubuntu and centos7 installation media mirroring.

2015-05-03

(R)?ex 1.2.0 released. See the release notes for more details.

2015-03-27

View the slides of the talk An introduction to Rex from Andy Beverley.

Conferences

2016-06-21

Training

Need Help?

Rex is a pure open source project, you can find community support in the following places:

Professional support is also available.

» Home » Docs » Rex Book (work in progress) » The Rex DSL » Using Environments

Using Environments

With environments it is easy to group your servers depending on the maturity of your configuration or your code.

You can create environments for dev, staging and production machines. There is no limit for environments, so you can create as much as you need.

The classic way is to have 3 environments. The development environment for integration tests, mostly with fewest machines. The staging environment, mostly with the same resource layers as production. And the production environment.

Creating Environments

Creating environments is as easy as creating groups. To create environments you can use the environment function. Inside an environment you can place everything that is specific for this environment (like authentication, server groups, tasks, ...).

# Rexfile
use Rex -feature => ['1.0'];

environment test => sub {
  user "root";
  password "b0x";

  group frontend   => "fe01.test";
  group middleware => "mw01.test";
  group dbwrite    => "dbm01.test";
};

environment stage => sub {
  user "root";
  password "b0xst4g3";

  group loadbalancer => "lb01.stage";
  group frontend     => "fe01.stage";
  group middleware   => "mw01.stage";
  group dbread       => "dbs01.stage";
  group dbwrite      => "dbm01.stage";
};

environment live => sub {
  user "admin";
  password "b0xl1v3";
  sudo_password "b0xl1v3";
  sudo TRUE;

  group loadbalancer => "lb[01..02].live";
  group frontend     => "fe[01..03].live";
  group middleware   => "mw[01..02].live";
  group dbread       => "dbs[01..02].live";
  group dbwrite      => "dbm01.live";
};

Running tasks

To run the task inside a special environment you have to use the cli option -E

$ rex -E stage $task

If you need to configure systems depending on the environment you can get the current environment inside a task with the environment function.

# Rexfile
task "prepare", group => "frontend", make {
  # configure ntp.conf depending on the environment
  my $ntp_server = case environment, {
                     test    => ["ntp01.test"],
                     stage   => ["ntp01.stage"],
                     live    => ["ntp01.live", "ntp02.live"],
                     default => ["ntp01.test"],
                   };

  file "/etc/ntp.conf",
    content   => template("templates/etc/ntp.conf", ntp_server => $ntp_server),
    owner     => "root",
    group     => "root",
    mode      => 644,
    on_change => make { service ntpd => "restart"; };
};

Environments and the CMDB

If you're using a CMDB to separate data from code you can also create YAML files for the different environments.

The lookup path for the default YAML CMDB is as follow:

The YAML files

# File: cmdb/default.yml
ntp_server:
  - ntp01.test
# File: cmdb/test/default.yml
ntp_server:
  - ntp01.test
# File: cmdb/stage/default.yml
ntp_server:
  - ntp01.stage
# File: cmdb/live/default.yml
ntp_server:
  - ntp01.live
  - ntp02.live

The Rexfile

To use the CMDB you have to require and configure the Rex::CMDB module first.

# Rexfile
use Rex -feature => ['1.0'];
use Rex::CMDB;

set cmdb => {
  type => "YAML",
  path => "./cmdb",
};

task "prepare", group => "frontend", make {
  # configure ntp.conf depending on the environment
  my $ntp_server = get cmdb "ntp_server";

  file "/etc/ntp.conf",
    content   => template("templates/etc/ntp.conf", ntp_server => $ntp_server),
    owner     => "root",
    group     => "root",
    mode      => 644,
    on_change => make { service ntpd => "restart"; };
};

Now you can run the task with rex -E test prepare.

Fork me on GitHub
Google Group / Twitter / GitHub / Mailinglist / irc.freenode.net #rex   -.รด.-   Disclaimer