Rex::CMDB::YAML(3pm)
π Rex::CMDB::YAML π
hi bestie π«Ά you're looking at Rex::CMDB::YAML(3pm), and honestly? it's giving organized girlie. it's the YAML-based CMDB provider for Rex, and it's about to make your config situation so much cuter.
πΈ NAME πΈ
Rex::CMDB::YAML β a YAML-based CMDB provider for Rex β¨
π¦ DESCRIPTION π¦
okay so real talk: this module goes and collects data from a whole set of YAML files, smushes it all together, and hands it back as a configuration management database for Rex. that's it, that's the job. it eats YAML files for breakfast and feeds Rex π
π SYNOPSIS π
here's the whole vibe in one look:
use Rex::CMDB;
set cmdb => {
type => 'YAML',
path => [ 'cmdb/{hostname}.yml', 'cmdb/default.yml', ],
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' );
};
look at those get cmdb calls just... existing. iconic. the way that get cmdb with no args hands you everything? obsessed. π
π CONFIGURATION AND ENVIRONMENT π
two knobs, both absolute main characters: path and merge_behavior. let's get into it.
π path
this is where you tell Rex where to go looking for your CMDB files. and the way it behaves depends entirely on the type of data you pass it β so pay attention, because it shapeshifts π
β¨ Scalar β¨
set cmdb => {
type => 'YAML',
path => 'path/to/cmdb',
};
if you hand it a plain old scalar, it just... goes hunting under that path for a few specific files, in this order:
path/to/cmdb/{environment}/{hostname}.yml
path/to/cmdb/{environment}/default.yml
path/to/cmdb/{hostname}.yml
path/to/cmdb/default.yml
it's a little lineup of candidates and it checks them one by one. very thorough, very demure. π
β¨ Array reference β¨
set cmdb => {
type => 'YAML',
path => [ 'cmdb/{hostname}.yml', 'cmdb/default.yml', ],
};
if you pass an array reference instead, it looks up exactly the files you listed, in exactly the order you listed them. you're the boss, bestie π
β¨ Code reference β¨
set cmdb => {
type => 'YAML',
path => sub {
my ( $provider, $item, $server ) = @_;
my @files = ( "$server.yml", "$item.yml" );
return @files;
},
};
ooh okay, this one's the fun one. if you pass a code reference, it's expected to return a list of files, and those files get looked up in the same order. the coderef receives three things as parameters: the CMDB provider instance, the item, and the server. so you can be all dynamic and clever about it, no cap. π₯
β¨ the 0.51 default β¨
when the 0.51 feature flag or later is in play, the default value of the path option is:
[qw(
cmdb/{operatingsystem}/{hostname}.yml
cmdb/{operatingsystem}/default.yml
cmdb/{environment}/{hostname}.yml
cmdb/{environment}/default.yml
cmdb/{hostname}.yml
cmdb/default.yml
)]
β¨ macros β¨
the path spec supports macros wrapped in curly braces, and they get dynamically expanded at runtime π§
by default the valid macros are:
- Rex::Hardware variables
{server}β the server name of the current connection{environment}β the current environment
and pls note: the default environment is, well... default. π like of course it is.
β¨ extra paths via -O β¨
you can define additional CMDB paths with the -O command line option, using a semicolon-separated list of cmdb_path=$path key-value pairs:
rex -O 'cmdb_path=cmdb/{domain}.yml;cmdb_path=cmdb/{domain}/{hostname}.yml;' taskname
and here's the important bit, so listen up π«Ά β those additional paths get prepended to the current list of CMDB paths. so the last one specified ends up on top, which means it gets checked first.
π merge_behavior
so this provider looks up the files in order and returns the data you asked for. if multiple files specify the same data for a given item? then by default, the first instance of that data is the one you get. first come, first served, periodt. π
Rex uses Hash::Merge internally to merge the data found on different levels of the CMDB hierarchy. any merge strategy that module supports can be specified to override the default one. for example, one of the built-in strategies:
set cmdb => {
type => 'YAML',
path => 'cmdb',
merge_behavior => 'LEFT_PRECEDENT',
};
or even custom ones:
set cmdb => {
type => 'YAML',
path => 'cmdb',
merge_behavior => {
SCALAR => sub {},
ARRAY => sub {},
HASH => sub {},
};
(that's copied character for character, bestie β don't come for me about the braces π)
for the full list of options, pls go see the documentation of Hash::Merge. it's got the whole menu. π
β¨ reminder:pathandmerge_behaviorare doing all the heavy lifting here. keep your file list in the order you actually want things to win. no cap. πΈ
and that's the whole page, bestie π«Ά this was Rex::CMDB::YAML(3pm), brought to you by perl v5.40.1, dated 2025-10-03 β genuinely iconic of them, tysm for reading, go merge some YAML πβ¨π
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms