Rex::CMDB(3pm)

πŸ‘‘ Rex::CMDB β€” the manual, bestie edition πŸ’–

okay so first things first: this is the man page for Rex::CMDB (a Perl module, section 3pm, filed under User Contributed Perl Documentation, and honestly? iconic of it). It gives you a ✨ function to access the CMDB ✨ β€” that's the configuration management database, your new bestie for keeping all the config deets in one place. πŸŽ€


🌸 NAME 🌸

Rex::CMDB β€” a function to access the CMDB (configuration management database). that's it, that's the name, no notes. πŸ’…


✨ DESCRIPTION ✨

So this module exports a function that lets you poke at a CMDB through one common interface β€” no cap. Every provider gets talked to the same way, so you don't gotta learn a new vibe for each one. πŸ¦‹

And here's the tea: when the 0.51 feature flag or later is in play, the CMDB is enabled by default, with Rex::CMDB::YAML as the default provider. so like, it just shows up ready to go. main character energy fr fr. πŸ‘‘


🌈 SYNOPSIS 🌈

here's the whole vibe in code, verbatim, don't touch it:

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' );
};

see how tidy? {hostname} gets swapped per host, cmdb/default.yml is the fallback boo, and LEFT_PRECEDENT is doing the merge choreography. πŸ’ƒ


πŸ’– EXPORTED FUNCTIONS πŸ’–

two of them, both precious, both giving:


πŸŽ€ set cmdb πŸŽ€

set cmdb => {
  type => 'YAML',
  %provider_options,
};

this one instantiates a specific type of CMDB provider with whatever options you hand over. it returns the provider instance so you can keep it around and use it. 🫢

heads up bestie: for the options each provider actually supports, you gotta go read that provider's own documentation. this page isn't gonna guess for you. πŸ™ˆ

πŸ¦‹ cmdb([$item, $server]) πŸ¦‹

the query function! the moment we've all been waiting for. it takes optional $item and $server and behaves like this:

  • no arguments at all β€” it gives you back the full CMDB data structure for the current connection. everything, the whole closet. 🧚
  • only a defined $item passed β€” you get just the value for that CMDB item, still for the current connection. one item, one vibe. ✨
  • only a defined $server passed β€” you get the whole CMDB data structure but for the given server instead. πŸ‘‘
  • both $item and $server defined β€” you get that specific item, for that specific server. chef's kiss, exactly what you asked for. πŸ’…

now, the plot twist: the value you get back is a Rex::Value, not a plain Perl thing. so if you wanna assign it to a Perl variable you're gonna need the get cmdb(...) form. like this, literally:

task 'prepare', 'server1', sub {
  my %all_information          = get cmdb;
  my $specific_item            = get cmdb('item');
  my $specific_item_for_server = get cmdb( 'item', 'server' );
};

and if caching is enabled? after the first query, this function caches the full data structure for the given server under the cache key:

cmdb/$CMDB_PROVIDER/$server

so subsequent hits are basically free. slay. πŸ”₯


πŸ’€ real talk reminder: use the get cmdb(...) form when assigning to Perl variables, because Rex::Value ain't gonna just plop into your my for you. iykyk.

and that's the whole page, bestie. this gem was documented under perl v5.40.1, dated 2025-10-03, and it's part of the Rex::CMDB(3pm) manual β€” User Contributed Perl Documentation, as always doing the absolute most. go configure something gorgeous. πŸ“βœ¨πŸ’œ

πŸ“¦ where this page comes from