Skip to content

Instantly share code, notes, and snippets.

@smbambling
Last active October 16, 2016 07:44
Show Gist options
  • Save smbambling/2f7c4bd92e3519fe4a00 to your computer and use it in GitHub Desktop.
Save smbambling/2f7c4bd92e3519fe4a00 to your computer and use it in GitHub Desktop.
Example Puppet Class to create PE Groups automatically from Role Classes
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