The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Rex::CMDB::TOML - TOML-based CMDB provider for Rex


This module collects and merges data from a set of TOML files to provide configuration management database for Rex.


    use Rex::CMDB;
    set cmdb => {
        type           => 'TOML',
        path           => [ 'cmdb/{hostname}.toml', 'cmdb/default.toml', ],
        merge_behavior => 'LEFT_PRECEDENT',
    task 'prepare', 'server1', sub {
        my $all_information          = get cmdb;
        my $specific_item            = get cmdb('item');
        my $specific_item_for_server = get cmdb( 'item', 'server' );



The path used to look for CMDB files. It supports various use cases depending on the type of data passed to it.

  • Scalar

        set cmdb => {
            type => 'TOML',
            path => 'path/to/cmdb',

    If a scalar is used, it tries to look up a few files under the given path:

  • Array reference

        set cmdb => {
            type => 'TOML',
            path => [ 'cmdb/{hostname}.yml', 'cmdb/default.yml', ],

    If an array reference is used, it tries to look up the mentioned files in the given order.

  • Code reference

        set cmdb => {
            type => 'TOML',
            path => sub {
                my ( $provider, $item, $server ) = @_;
                my @files = ( "$server.yml", "$item.yml" );
                return @files;

    If a code reference is passed, it should return a list of files that would be looked up in the same order. The code reference gets the CMDB provider instance, the item, and the server as parameters.

When the 0.51 feature flag or later is used, the default value of the path option is:


The path specification supports macros enclosed within curly braces, which are dynamically expanded during runtime. By default, the valid macros are Rex::Hardware variables, {server} for the server name of the current connection, and {environment} for the current environment.

Please note that the default environment is, well, default.

You can define additional CMDB paths via the -O command line option by using a semicolon-separated list of cmdb_path=$path key-value pairs:

 rex -O 'cmdb_path=cmdb/{domain}.toml;cmdb_path=cmdb/{domain}/{hostname}.toml;' taskname

Those additional paths will be prepended to the current list of CMDB paths (so the last one specified will get on top, and thus checked first).


This CMDB provider looks up the specified files in order, and returns the requested data. If multiple files specify the same data for a given item, then the first instance of the data will be returned by default.

Rex uses Hash::Merge internally to merge the data found on different levels of the CMDB hierarchy. Any merge strategy supported by that module can be specified to override the default one. For example one of the built-in strategies:

    set cmdb => {
        type           => 'TOML',
        path           => 'cmdb',
        merge_behavior => 'LEFT_PRECEDENT',

Or even custom ones:

    set cmdb => {
        type           => 'TOML',
        path           => 'cmdb',
        merge_behavior => {
            SCALAR => sub {},
            ARRAY  => sub {},
            HASH   => sub {},

For the full list of options, please see the documentation of Hash::Merge.


Specifies if roles should be used or not.

This value is a Perl boolean and defaults to '0'.


The path to look for roles under.

By default it is 'cmdb/roles'.


If it should die or warn upon TOML parsing error.

This is a Perl boolean and the default is '1', to die.


If a specified role not being able to be found is fatal.

This is a Perl boolean and the default is '1', to die.


If it should merge the roles into the config instead of the default of merging the config into the roles.

This is a Perl boolean and the default is '0', meaning the config will over write anything in the roles with the default merge_behavior settings.


NOTE: Currently only compatible with scalar value for paths.

If use_roles has been set to true, when loading a config file, it will check for value 'roles' and if that value is a array, it will then go through and look foreach of those roles under the roles_path.

So lets say we have the config below.

    foo = "bar"
    roles = [ 'test' ]

It will then load look under the roles_path for the file 'test.toml', which with the default settings would be 'cmdb/roles/test.toml'.

Lets say we have the the role file set as below.

    ping = "yes"
    misses = 3

This means with the value for ping will be 'no' as the default of 'yes' is being overriden by the config value.

Somethings to keep in mind when using this.

1: Don't define a value you intend to use in a role in any of the config files that will me merged unless you want it to always override anything a role may import. So with like the example above, you would want to avoid putting ping='no' in the default toml file and only set it if you want to override that role in like the toml config for that host.

2: Roles may not include roles. While it won't error or the like, they also won't be reeled in.