Created
October 19, 2021 17:39
-
-
Save ferki/22e21a527e3520db87f0dcac8f5fdcb6 to your computer and use it in GitHub Desktop.
Rex dynamic CMDB with roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v5.24; # for postfix dereferencing below | |
use strict; | |
use warnings; | |
use Rex -feature => [ '1.4', 'exec_autodie' ]; | |
use Rex::CMDB; | |
use File::Spec; | |
use YAML qw(LoadFile); | |
set cmdb => { | |
type => 'YAML', | |
path => sub { | |
my ( $self, $item, $host ) = @_; | |
my $cmdb_directory = '/my/path/to/cmdb'; | |
my $server_file = File::Spec->join( $cmdb_directory, 'hosts', "$host.yml" ); | |
my @cmdb_files = ($server_file); | |
my $server_yaml = LoadFile($server_file); | |
my @roles_files = map { File::Spec->join( $cmdb_directory, 'roles', "$_.yml" ) } | |
$server_yaml->{roles}->@*; | |
push @cmdb_files, @roles_files; | |
return @cmdb_files; | |
}, | |
merge_behavior => 'LEFT_PRECEDENT', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment