.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" 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::YAML 3pm" .TH Rex::CMDB::YAML 3pm "2023-08-09" "perl v5.36.0" "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::YAML \- YAML\-based CMDB provider for Rex .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module collects and merges data from a set of \s-1YAML\s0 files to provide configuration management database for Rex. .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 \*(Aqprepare\*(Aq, \*(Aqserver1\*(Aq, sub { \& my %all_information = get cmdb; \& my $specific_item = get cmdb(\*(Aqitem\*(Aq); \& my $specific_item_for_server = get cmdb( \*(Aqitem\*(Aq, \*(Aqserver\*(Aq ); \& }; .Ve .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" .SS "path" .IX Subsection "path" The path used to look for \s-1CMDB\s0 files. It supports various use cases depending on the type of data passed to it. .IP "\(bu" 4 Scalar .Sp .Vb 4 \& set cmdb => { \& type => \*(AqYAML\*(Aq, \& path => \*(Aqpath/to/cmdb\*(Aq, \& }; .Ve .Sp If a scalar is used, it tries to look up a few files under the given path: .Sp .Vb 4 \& path/to/cmdb/{environment}/{hostname}.yml \& path/to/cmdb/{environment}/default.yml \& path/to/cmdb/{hostname}.yml \& path/to/cmdb/default.yml .Ve .IP "\(bu" 4 Array reference .Sp .Vb 4 \& set cmdb => { \& type => \*(AqYAML\*(Aq, \& path => [ \*(Aqcmdb/{hostname}.yml\*(Aq, \*(Aqcmdb/default.yml\*(Aq, ], \& }; .Ve .Sp If an array reference is used, it tries to look up the mentioned files in the given order. .IP "\(bu" 4 Code reference .Sp .Vb 8 \& set cmdb => { \& type => \*(AqYAML\*(Aq, \& path => sub { \& my ( $provider, $item, $server ) = @_; \& my @files = ( "$server.yml", "$item.yml" ); \& return @files; \& }, \& }; .Ve .Sp 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 \s-1CMDB\s0 provider instance, the item, and the server as parameters. .PP When the 0.51 feature flag or later is used, the default value of the \f(CW\*(C`path\*(C'\fR option 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 The path specification supports macros enclosed within curly braces, which are dynamically expanded during runtime. By default, the valid macros are Rex::Hardware variables, \f(CW\*(C`{server}\*(C'\fR for the server name of the current connection, and \f(CW\*(C`{environment}\*(C'\fR for the current environment. .PP Please note that the default environment is, well, \f(CW\*(C`default\*(C'\fR. .PP You can define additional \s-1CMDB\s0 paths via the \f(CW\*(C`\-O\*(C'\fR command line option by using a semicolon-separated list of \f(CW\*(C`cmdb_path=$path\*(C'\fR 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). .SS "merge_behavior" .IX Subsection "merge_behavior" This \s-1CMDB\s0 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. .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 5 \& set cmdb => { \& type => \*(AqYAML\*(Aq, \& path => \*(Aqcmdb\*(Aq, \& merge_behavior => \*(AqLEFT_PRECEDENT\*(Aq, \& }; .Ve .PP Or even custom ones: .PP .Vb 8 \& set cmdb => { \& type => \*(AqYAML\*(Aq, \& path => \*(Aqcmdb\*(Aq, \& merge_behavior => { \& SCALAR => sub {}, \& ARRAY => sub {}, \& HASH => sub {}, \& }; .Ve .PP For the full list of options, please see the documentation of Hash::Merge.