-
Notifications
You must be signed in to change notification settings - Fork 461
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
apt: Fix all strict variable cases. #449
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
@@ -68,7 +72,7 @@ | |||
case $::lsbdistid { | |||
'ubuntu', 'debian': { | |||
$distid = $::lsbdistid | |||
$distcodename = $::lsbdistcodename | |||
$distcodename = $xfacts['lsbdistid'] |
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.
Shouldn't this be $xfacts['lsbdistcodename']
?
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.
Damn it.
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
$facts
hash lookup instead which will return undef/nil for things that aren't set instead of them not being defined at all.