summaryrefslogtreecommitdiff
path: root/lib/chef/node.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-04-12 18:39:34 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-04-12 18:45:55 -0700
commit6607b130fe16fa9f28300548d01561d04da54eae (patch)
tree5a317c6e770683e3b99f177f4fbb3fe1346d32b6 /lib/chef/node.rb
parent3a87c705090c7f44d51666c0bf88add9c2445e9a (diff)
downloadchef-6607b130fe16fa9f28300548d01561d04da54eae.tar.gz
Allow empty strings in -o to result in empty override run listlcg/empty-override-runlist
Previously this was not possible. Now you can do this: ``` chef-client -o "" ./foo.rb ``` And it will only run foo.rb and not any of the recipes in your run_list at all. Node will not be saved at the end. Useful to one-shot something like keyrotation (which still needs keys and needs to talk to the chef server API, so this is a different use case from simple chef-apply). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r--lib/chef/node.rb30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 9b67f27f14..c945bb640f 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -300,13 +300,37 @@ class Chef
@primary_runlist
end
- attr_writer :override_runlist
+ # This boolean can be useful to determine if an override_runlist is set, it can be true
+ # even if the override_runlist is empty.
+ #
+ # (Mutators can set the override_runlist so any non-empty override_runlist is considered set)
+ #
+ # @return [Boolean] if the override run list has been set
+ def override_runlist_set?
+ !!@override_runlist_set || !override_runlist.empty?
+ end
+
+ # Accessor for override_runlist (this cannot set an empty override run list)
+ #
+ # @params args [Array] override run list to set
+ # @return [Chef::RunList] the override run list
def override_runlist(*args)
- args.length > 0 ? @override_runlist.reset!(args) : @override_runlist
+ return @override_runlist if args.length == 0
+ @override_runlist_set = true
+ @override_runlist.reset!(args)
+ end
+
+ # Setter for override_runlist which allows setting an empty override run list and marking it to be used
+ #
+ # @params array [Array] override run list to set
+ # @return [Chef::RunList] the override run list
+ def override_runlist=(array)
+ @override_runlist_set = true
+ @override_runlist.reset!(array)
end
def select_run_list
- @override_runlist.empty? ? @primary_runlist : @override_runlist
+ override_runlist_set? ? @override_runlist : @primary_runlist
end
# Returns an Array of roles and recipes, in the order they will be applied.