You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using only_if / not_if with a String, i.e. passing in a command instead of Ruby code, it does not appear easily possible to lazily evaluate node attributes.
For example, the following code will evaluate the value of node['some-attribute'] at compile-time:
It'd be nice to have something like the following, but I realize that implementing this literally may be confusing since only_if already lazily evaluates Ruby code (see also #10243).
I don't know exactly how common this need is, but it seems like there's an opportunity for syntactic sugar here that would make writing these kinds of things more pleasant.
Current Alternative
It is possible for a user to define a custom resource, or do something like only_if { shell_out("some-command #{node['some-attribute']}").status.success? }.
msg="#{@parent_resource.name} was given a guard_interpreter of #{@parent_resource.guard_interpreter}, "
msg << "but not given a command as a string. guard_interpreter does not support blocks (because they just contain ruby)."
raiseArgumentError,msg
end
@guard_interpreter=nil
@command,@command_opts=nil,nil
else
# command was passed, but it wasn't a String
raiseArgumentError,"Invalid only_if/not_if command, expected a string: #{command.inspect} (#{command.class})"
end
end
The tough part would be deciding what the syntax should be, because lazy might not be a good fit since it could be confusing. I imagine one way might be to have the user pass an Array, and have the guard_interpreter first de-lazy any array elements that are lazy, for example:
Describe the Enhancement:
When using
only_if
/not_if
with aString
, i.e. passing in a command instead of Ruby code, it does not appear easily possible to lazily evaluate node attributes.For example, the following code will evaluate the value of
node['some-attribute']
at compile-time:It'd be nice to have something like the following, but I realize that implementing this literally may be confusing since
only_if
already lazily evaluates Ruby code (see also #10243).Describe the Need:
I don't know exactly how common this need is, but it seems like there's an opportunity for syntactic sugar here that would make writing these kinds of things more pleasant.
Current Alternative
It is possible for a user to define a custom resource, or do something like
only_if { shell_out("some-command #{node['some-attribute']}").status.success? }
.Can We Help You Implement This?:
Sure, I think the relevant code is here:
chef/lib/chef/resource/conditional.rb
Lines 56 to 77 in 4ce99c4
The tough part would be deciding what the syntax should be, because
lazy
might not be a good fit since it could be confusing. I imagine one way might be to have the user pass anArray
, and have the guard_interpreter first de-lazy any array elements that are lazy, for example:The text was updated successfully, but these errors were encountered: