Last active
October 16, 2016 07:44
-
-
Save smbambling/2f7c4bd92e3519fe4a00 to your computer and use it in GitHub Desktop.
Example Puppet Class to create PE Groups automatically from Role Classes
This file contains 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
class node_manager::create_groups { | |
$environments = split(fetch_environments(), ',') | |
$environments.each | $env | { | |
$classes = split(fetch_resource_types("production", "^role::"), ',') | |
$classes.each | $class | { | |
$full_name = $class | |
$short_name = regsubst($class, 'role::', '') | |
$group_name = regsubst($short_name, '_', ' ', 'G') | |
$cap_group_name = join(capitalize(split($group_name, ' ')), ' ') | |
node_group { "$env-$cap_group_name": | |
ensure => 'present', | |
classes => {"${full_name}" => {}}, | |
environment => 'production', | |
override_environment => false, | |
parent => 'All Nodes', | |
rule => ['and', ['=', ['fact', 'role'], "${short_name}"]], | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment