1Rex::CMDB::YAML(3) User Contributed Perl Documentation Rex::CMDB::YAML(3)
2
3
4
6 Rex::CMDB::YAML - YAML-based CMDB provider for Rex
7
9 This module collects and merges data from a set of YAML files to
10 provide configuration management database for Rex.
11
13 use Rex::CMDB;
14
15 set cmdb => {
16 type => 'YAML',
17 path => [ 'cmdb/{hostname}.yml', 'cmdb/default.yml', ],
18 merge_behavior => 'LEFT_PRECEDENT',
19 };
20
21 task 'prepare', 'server1', sub {
22 my %all_information = get cmdb;
23 my $specific_item = get cmdb('item');
24 my $specific_item_for_server = get cmdb( 'item', 'server' );
25 };
26
28 path
29 The path used to look for CMDB files. It supports various use cases
30 depending on the type of data passed to it.
31
32 · Scalar
33
34 set cmdb => {
35 type => 'YAML',
36 path => 'path/to/cmdb',
37 };
38
39 If a scalar is used, it tries to look up a few files under the
40 given path:
41
42 path/to/cmdb/{environment}/{hostname}.yml
43 path/to/cmdb/{environment}/default.yml
44 path/to/cmdb/{hostname}.yml
45 path/to/cmdb/default.yml
46
47 · Array reference
48
49 set cmdb => {
50 type => 'YAML',
51 path => [ 'cmdb/{hostname}.yml', 'cmdb/default.yml', ],
52 };
53
54 If an array reference is used, it tries to look up the mentioned
55 files in the given order.
56
57 · Code reference
58
59 set cmdb => {
60 type => 'YAML',
61 path => sub {
62 my ( $provider, $item, $server ) = @_;
63 my @files = ( "$server.yml", "$item.yml" );
64 return @files;
65 },
66 };
67
68 If a code reference is passed, it should return a list of files
69 that would be looked up in the same order. The code reference gets
70 the CMDB provider instance, the item, and the server as parameters.
71
72 When the 0.51 feature flag or later is used, the default value of the
73 "path" option is:
74
75 [qw(
76 cmdb/{operatingsystem}/{hostname}.yml
77 cmdb/{operatingsystem}/default.yml
78 cmdb/{environment}/{hostname}.yml
79 cmdb/{environment}/default.yml
80 cmdb/{hostname}.yml
81 cmdb/default.yml
82 )]
83
84 The path specification supports macros enclosed within curly braces,
85 which are dynamically expanded during runtime. By default, the valid
86 macros are Rex::Hardware variables, "{server}" for the server name of
87 the current connection, and "{environment}" for the current
88 environment.
89
90 Please note that the default environment is, well, "default".
91
92 You can define additional CMDB paths via the "-O" command line option
93 by using a semicolon-separated list of "cmdb_path=$path" key-value
94 pairs:
95
96 rex -O 'cmdb_path=cmdb/{domain}.yml;cmdb_path=cmdb/{domain}/{hostname}.yml;' taskname
97
98 Those additional paths will be prepended to the current list of CMDB
99 paths (so the last one specified will get on top, and thus checked
100 first).
101
102 merge_behavior
103 This CMDB provider looks up the specified files in order, and returns
104 the requested data. If multiple files specify the same data for a given
105 item, then the first instance of the data will be returned by default.
106
107 Rex uses Hash::Merge internally to merge the data found on different
108 levels of the CMDB hierarchy. Any merge strategy supported by that
109 module can be specified to override the default one. For example one of
110 the built-in strategies:
111
112 set cmdb => {
113 type => 'YAML',
114 path => 'cmdb',
115 merge_behavior => 'LEFT_PRECEDENT',
116 };
117
118 Or even custom ones:
119
120 set cmdb => {
121 type => 'YAML',
122 path => 'cmdb',
123 merge_behavior => {
124 SCALAR => sub {},
125 ARRAY => sub {},
126 HASH => sub {},
127 };
128
129 For the full list of options, please see the documentation of
130 Hash::Merge.
131
132
133
134perl v5.32.1 2021-03-06 Rex::CMDB::YAML(3)