Created
December 21, 2017 01:05
-
-
Save natemccurdy/07e8f08f0b1811e8cbb8996bd08e5915 to your computer and use it in GitHub Desktop.
site.pp classification schemes
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
# OPTION A | |
# - Hard failure if pp_role isn't defined. | |
# - No check to see if the role exists | |
node default { | |
# Save the trusted pp_role to a shorter variable so it's easier to work with. | |
$role = $trusted['extensions']['pp_role'] | |
case $role { | |
default: { | |
include $role | |
} | |
undef, '': { | |
fail("${trusted['certname']} does not have a pp_role trusted fact!") | |
} | |
} | |
} | |
# OPTION B | |
# - Warning if pp_role not defined | |
# - Check to see if the role exists | |
# - Fall back to using the base profile | |
node default { | |
# Save the trusted pp_role to a shorter variable so it's easier to work with. | |
$role = $trusted['extensions']['pp_role'] | |
case $role { | |
default: { | |
# Check if the role class has been defined. | |
# Include it if so. If not, include the base profile and a warning. | |
if defined($role) { | |
include $role | |
} else { | |
notify { "No matching role for ${role} found": | |
loglevel => 'warning', | |
} | |
include profile::base | |
} | |
} | |
undef, '': { | |
notify { "${trusted['certname']} does not have a pp_role trusted fact!": | |
loglevel => 'warning', | |
} | |
include profile::base | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
defined(Type[Class[role::foo]])
is a more specific way of checking that a class exists and can be included.defined('role::foo')
doesn't distinguish between classes and defined types.Also of note,
defined(Class[role::foo])
checks if the class has already been included in the catalog (which isn't what we want here).