Conversation
fd22eb1 to
439615c
Compare
|
@hlindberg I've had to do a few horrible things here for strict variables, mainly not being able to bind fact values on parameters because it might not be set. This wouldn't be a problem if we didn't explicitly have test cases that check if for example Do we have any way to make this better except for using the |
|
Since there is no way to enforce that the $facts hash is available on 3x from within a module (and users would probably not be happy about it since it may run into problems if users are using $facts as a regular variable).
I can however imagine writing a compatibility function that is invoked early in the process that adds global variables with the value 'undef' - the Puppet Code can then continue to look at the variables since they will then not be missing. Then at least, you do not have to have the defined?("$name") all over the place. |
|
Hm, then there is $caller_module_name |
|
yet another alternative would be to write a function that does the same as $facts. That would require squirreling away the data that is put into $facts to allow this function to find it later. |
|
I logged this https://tickets.puppetlabs.com/browse/PUP-4066 for the built in variables case |
|
Thanks @hlindberg! |
019b926 to
2fd57c9
Compare
|
Right, so using |
6e36831 to
d372664
Compare
manifests/params.pp
Outdated
There was a problem hiding this comment.
Shouldn't this be $xfacts['lsbdistcodename']?
da5e559 to
d935338
Compare
A few of these fixes are absolutely horrendous but we have no choice as we need to stay current- and future-parser compatible for now. Once we can go Puppet 4 only we can use the `$facts` hash lookup instead which will return undef/nil for things that aren't set instead of them not being defined at all.
d935338 to
c57d2dd
Compare
apt: Fix all strict variable cases.
|
thanks @daenney ! |
|
good work - looks less horrible now |
|
Yes, and with #450 merged we'll have a full set of 'guarded' facts. I wanted to write it as a function but I didn't really feel like figuring out how to get to those variables from Puppet. If someone would like to add that to stdlib, much obliged. |
|
see the file runtime3_support.rb method get_variable_value(name, o, scope). And remember when in a 3x function, self is an instance of Scope. The --strict_variables will raise a ruby exception (the symbo :undefined_variable) - you understand when you look at the code. Here is the method in question |
A few of these fixes are absolutely horrendous but we have no choice as we need to stay current- and future-parser compatible for now.
Once we can go Puppet 4 only we can use the
$factshash lookup instead which will return undef/nil for things that aren't set instead of them not being defined at all.