summaryrefslogtreecommitdiff
path: root/lib/chef/application
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2020-03-17 23:10:44 -0400
committerBryan McLellan <btm@loftninjas.org>2020-03-23 12:57:09 -0400
commitf8545babece542e9741d810bbbbebfcb3491bf64 (patch)
tree201109c454e7dd4967f7e9eafc25b735e5e64f19 /lib/chef/application
parentf59c0443f43f6d8f0e7d95a030b34346c6cce482 (diff)
downloadchef-f8545babece542e9741d810bbbbebfcb3491bf64.tar.gz
Add YAML support to 'chef-apply'
Allows `chef-apply foo.yml` to be parsed as a YAML recipe. Also adds a configuration flag to enable `chef-apply foo.whatever --yaml`. Signed-off-by: Bryan McLellan <btm@loftninjas.org>
Diffstat (limited to 'lib/chef/application')
-rw-r--r--lib/chef/application/apply.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index 4718e8750b..e242f91d29 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -105,6 +105,12 @@ class Chef::Application::Apply < Chef::Application
description: "Enable whyrun mode.",
boolean: true
+ option :yaml,
+ long: "--yaml",
+ description: "Parse recipe as YAML",
+ boolean: true,
+ default: false
+
option :profile_ruby,
long: "--[no-]profile-ruby",
description: "Dump complete Ruby call graph stack of entire #{Chef::Dist::PRODUCT} run (expert only).",
@@ -148,6 +154,10 @@ class Chef::Application::Apply < Chef::Application
if file_name.nil?
Chef::Application.fatal!("No recipe file was provided", Chef::Exceptions::RecipeNotFound.new)
else
+ if file_name =~ /\.yml$/
+ logger.info "Recipe file name ends with .yml, parsing as YAML"
+ config[:yaml] = true
+ end
recipe_path = File.expand_path(file_name)
unless File.exist?(recipe_path)
Chef::Application.fatal!("No file exists at #{recipe_path}", Chef::Exceptions::RecipeNotFound.new)
@@ -198,7 +208,11 @@ class Chef::Application::Apply < Chef::Application
@recipe_text, @recipe_fh = read_recipe_file @recipe_filename
end
recipe, run_context = get_recipe_and_run_context
- recipe.instance_eval(@recipe_text, @recipe_filename, 1)
+ if config[:yaml]
+ recipe.from_yaml(@recipe_text)
+ else
+ recipe.instance_eval(@recipe_text, @recipe_filename, 1)
+ end
runner = Chef::Runner.new(run_context)
catch(:end_client_run_early) do
begin