New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BREAKING: refactor hiera data lookup #76
BREAKING: refactor hiera data lookup #76
Conversation
c056a36
to
7b1e233
Compare
manifests/init.pp
Outdated
@@ -86,11 +86,15 @@ | |||
} | |||
|
|||
if $mounts { | |||
$data = hiera_hash('autofs::mounts', $mounts) | |||
create_resources('autofs::mount', $data) | |||
lookup('autofs::mounts', { default_value => $mounts, merge => hash }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't use merge => deep
then there's no point in doing the lookup at all. You may as well just use $mounts.
manifests/init.pp
Outdated
@@ -86,11 +86,15 @@ | |||
} | |||
|
|||
if $mounts { | |||
$data = hiera_hash('autofs::mounts', $mounts) | |||
create_resources('autofs::mount', $data) | |||
lookup('autofs::mounts', { default_value => $mounts, merge => hash }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the merge strategy should be defined in hiera itself.
https://docs.puppet.com/puppet/5.1/hiera_merging.html#configuring-merge-behavior-in-hiera-data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the merge strategy is defined as lookup_options
there is also no use of calling lookup() for autofs::mounts
because the automatic parameter lookup will do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm avoiding anything that is not explicitly available in Puppet 4.7.0
While Hiera 4 does exists, it's technically "beta" until Puppet 4.9.0, hence why I'm defining merge strategy in the lookup instead. I'm am unsure if lookup_options
is available for Hiera 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. Realistically I think using lookup_options would mean we'd only support a very recent puppet 4.10.x (think 4.10.6) or puppet 5. Hiera 5 was officially available (and not experimental) since 4.9.0, but I think it was also really buggy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like using pure puppet functions and letting hiera just apply on class params.
manifests/init.pp
Outdated
Optional[Hash] $mounts = undef, | ||
Optional[Hash] $maps = undef, | ||
Optional[Hash] $mounts = {}, | ||
Optional[Hash] $maps = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional can be dropped if you set a default. It can even be Hash[String, Hash]
manifests/init.pp
Outdated
create_resources('autofs::map',$_datamaps) | ||
} | ||
$mounts.each |String $mount, Hash $attributes| { | ||
autofs::mount { $mount: * => $attributes } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd indenting here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but probably commits want squashing before merge.
Hiera lookups now use the default automatic lookup merge options. README has been updated to note how to perform a Hash or Deep merge from within your data file using the lookup_options key
380cdec
to
36b81ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for minimal code
Replacing the deprecated hiera_hash functions with the lookup function. Additionally, I have replaced the
create_resources
function calls using the method found at https://docs.puppet.com/puppet/5.1/lang_resources_advanced.html#implementing-the-createresources-functionThat replacement gives users and contributors alike a better idea as to what the code is actually doing when generating the defined resources.