.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Rex::CMDB 3pm" .TH Rex::CMDB 3pm "2020-09-18" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Rex::CMDB \- Function to access the CMDB (configuration management database) .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module exports a function to access a \s-1CMDB\s0 via a common interface. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Rex::CMDB; \& \& set cmdb => { \& type => \*(AqYAML\*(Aq, \& path => [ \& \*(Aqcmdb/{hostname}.yml\*(Aq, \& \*(Aqcmdb/default.yml\*(Aq, \& ], \& merge_behavior => \*(AqLEFT_PRECEDENT\*(Aq, \& }; \& \& task "prepare", "server1", sub { \& my $virtual_host = get cmdb("vhost"); \& my %all_information = get cmdb; \& }; .Ve .SH "EXPORTED FUNCTIONS" .IX Header "EXPORTED FUNCTIONS" .SS "set cmdb" .IX Subsection "set cmdb" \&\s-1CMDB\s0 is enabled by default, with Rex::CMDB::YAML as default provider. .PP The path option specifies an ordered list of places to look for \s-1CMDB\s0 information. The path specification supports any Rex::Hardware variable as macros, when enclosed within curly braces. Macros are dynamically expanded during runtime. The default path settings is: .PP .Vb 8 \& [qw( \& cmdb/{operatingsystem}/{hostname}.yml \& cmdb/{operatingsystem}/default.yml \& cmdb/{environment}/{hostname}.yml \& cmdb/{environment}/default.yml \& cmdb/{hostname}.yml \& cmdb/default.yml \& )] .Ve .PP Please note that the default environment is, well, \*(L"default\*(R". .PP You can define additional \s-1CMDB\s0 paths via the `\-O` command line option by using a semicolon-separated list of `cmdb_path=path` key-value pairs: .PP .Vb 1 \& rex \-O \*(Aqcmdb_path=cmdb/{domain}.yml;cmdb_path=cmdb/{domain}/{hostname}.yml;\*(Aq taskname .Ve .PP Those additional paths will be prepended to the current list of \s-1CMDB\s0 paths (so the last one specified will get on top, and thus checked first). .PP The \s-1CMDB\s0 module looks up the specified files in order and then returns the requested data. If multiple files specify the same data for a given case, then the first instance of the data will be returned by default. .PP Rex uses Hash::Merge internally to merge the data found on different levels of the \s-1CMDB\s0 hierarchy. Any merge strategy supported by that module can be specified to override the default one. For example one of the built-in strategies: .PP .Vb 1 \& merge_behavior => \*(AqLEFT_PRECEDENT\*(Aq .Ve .PP Or even custom ones: .PP .Vb 5 \& merge_behavior => { \& SCALAR => { ... }, \& ARRAY => { ... }, \& HASH => { ... }, \& } .Ve .PP For full list of options, please see the documentation of Hash::Merge. .ie n .SS "cmdb([$item, $server])" .el .SS "cmdb([$item, \f(CW$server\fP])" .IX Subsection "cmdb([$item, $server])" Function to query a \s-1CMDB.\s0 If this function is called without \f(CW$item\fR it should return a hash containing all the information for the requested server. If \f(CW$item\fR is given it should return only the value for \f(CW$item\fR. .PP .Vb 4 \& task "prepare", "server1", sub { \& my $virtual_host = get cmdb("vhost"); \& my %all_information = get cmdb; \& }; .Ve