summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2015-09-16 16:17:00 -0700
committerdanielsdeleo <dan@chef.io>2015-09-21 09:07:28 -0700
commit3bffbc968d4dc76cd6992c603f849cf46fd759dc (patch)
tree5b3e67923977c8dcf9b0951bd83b62dcd8291f62 /lib
parent3da8700c1c88a44488732bae47bcc5b1cb545ca2 (diff)
downloadchef-3bffbc968d4dc76cd6992c603f849cf46fd759dc.tar.gz
Apply a named_run_list in policy builder via configuration
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/policy_builder/policyfile.rb36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index 69ef485e14..bb9593eb36 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -170,6 +170,8 @@ class Chef
#
# @return [RunListExpansionIsh] A RunListExpansion duck-type.
def expand_run_list
+ CookbookCacheCleaner.instance.skip_removal = true if named_run_list_requested?
+
node.run_list(run_list)
node.automatic_attrs[:roles] = []
node.automatic_attrs[:recipes] = run_list_expansion_ish.recipes
@@ -253,7 +255,14 @@ class Chef
# @api private
def run_list
- policy["run_list"]
+ if named_run_list_requested?
+ named_run_list or
+ raise ConfigurationError,
+ "Policy '#{retrieved_policy_name}' revision '#{revision_id}' does not have named_run_list '#{named_run_list_name}'" +
+ "(available named_run_lists: [#{available_named_run_lists.join(', ')}])"
+ else
+ policy["run_list"]
+ end
end
# @api private
@@ -441,6 +450,11 @@ class Chef
end
# @api private
+ def revision_id
+ policy["revision_id"]
+ end
+
+ # @api private
def http_api
@api_service ||= Chef::REST.new(config[:chef_server_url])
end
@@ -462,6 +476,26 @@ class Chef
Chef.set_run_context(run_context)
end
+ def retrieved_policy_name
+ policy["name"]
+ end
+
+ def named_run_list
+ policy["named_run_lists"] && policy["named_run_lists"][named_run_list_name]
+ end
+
+ def available_named_run_lists
+ (policy["named_run_lists"] || {}).keys
+ end
+
+ def named_run_list_requested?
+ !!Chef::Config[:named_run_list]
+ end
+
+ def named_run_list_name
+ Chef::Config[:named_run_list]
+ end
+
def compat_mode_manifest_for(cookbook_name, lock_data)
xyz_version = lock_data["dotted_decimal_identifier"]
rel_url = "cookbooks/#{cookbook_name}/#{xyz_version}"