summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/defined_with_params.rb
AgeCommit message (Collapse)Author
2017-06-14(MODULES-5095) Workaround for PUP-7650Thomas Hallgren
This commit adds a simple workaround for the problem described in PUP-7650. The workaround is harmless and can remain in place regardless of if the fix for PUP-7650 is in place or not.
2017-05-09(PE-20308) Also fix defined type strings & referencesHunter Haugen
2017-04-26(PE-20308) Correct boundary for 4.5 vs 4.6Hunter Haugen
2017-04-25(PE-20308) Pass a literal type and not a string to findresourceHunter Haugen
- `defined_with_params` calls `findresource(reference.to_s)` - `findresource` is https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/parser/compiler.rb#L407 and points to https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L352 - This calls `Puppet::Resource.new` with the type https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L366 - This ends up calling `resource_type` via https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L317-L319 and that ends up declaring the type via the autoloader api at https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L390 - But why does the autoloader API fail to find it in the current environment? - Okay, so when the autoloader is trying to find the type, it uses the typeloader to look it up in the current environment https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/metatype/manager.rb#L171 - this calls `get_file` and `mark_loaded` https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/util/autoload.rb#L64-L67 Suggested workaround is to pass a literal type instead of a string to `findresource` to fix in stdlib, and also to fix loading/requiring of type in core puppet. This seems to affect more recent versions of puppet, so fallback to original behavior on pre-4.5
2016-06-30(MODULES-3543) Fixup defined_with_params to work on all puppet versionsDavid Schmitt
2016-06-29(MODULES-3543) Fix define_with_params to handle undef properlyDavid Schmitt
As described in PUP-6422, ensure_resources('File[/tmp/a]', { owner => undef }) would not actually create the file. This fixes it, and adds tests to prove it.
2012-08-15Revert "Revert "Merge pull request #86 from bodepd/ensure_resource""Dan Bode
This reverts commit 1e0983362464e8f2832239b09cdbc9175a51e6ec.
2012-08-14Revert "Merge pull request #86 from bodepd/ensure_resource"Jeff McCune
This reverts commit 42ddd7fe54f37b84e34b4a005de2249e53f07469, reversing changes made to 53243605b28fc31618d079155c86b37b4e88a6ca.
2012-08-13Handle undef for parameter argumentDan Bode
This commit adds better handling of the case where undef is passed as the parameter value. This works by converting '' into []
2012-08-13Add function ensure_resource and defined_with_paramsDan Bode
This commit adds 2 new functions with unit tests. defined_with_params works similarily to puppet's defined function, except it allows you to also specify a hash of params. defined_with_params will return true if a resource also exists that matches the specified type/title (just like with defined) as well as all of the specified params. ensure_resource is a function that basically combines defined_with_params with create_resources to conditionally create resources only if the specified resource (title, type, params) does not already exist. These functions are created to serve as an alternative to using defined as follows: if ! defined(Package['some_package']) { package { 'some_package': ensure => present, } The issue with this usage is that there is no guarentee about what parameters were set in the previous definition of the package that made its way into the catalog. ensure_resource could be used instead, as: ensure_resource('package', 'some_package', { 'ensure' => 'present' }) This will creat the package resources only if another resource does not exist with the specified parameters.