Method: Bolt::PlanCreator.create_plan
- Defined in:
- lib/bolt/plan_creator.rb
.create_plan(plans_path, plan_name, is_puppet: false, script: nil) ⇒ Object
Create a new plan from the plan templates based on which language the user configured, and whether the plan wraps a script.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bolt/plan_creator.rb', line 62 def self.create_plan(plans_path, plan_name, is_puppet: false, script: nil) _, name_segments, basename = segment_plan_name(plan_name) dir_path = plans_path.join(*name_segments) begin FileUtils.mkdir_p(dir_path) rescue Errno::EEXIST => e raise Bolt::Error.new( "#{e.}; unable to create plan directory '#{dir_path}'", 'bolt/existing-file-error' ) end type = is_puppet ? 'pp' : 'yaml' plan_path = dir_path + "#{basename}.#{type}" plan_template = if is_puppet && script puppet_script_plan(plan_name, script) elsif is_puppet puppet_plan(plan_name) elsif script yaml_script_plan(script) else yaml_plan(plan_name) end begin File.write(plan_path, plan_template) rescue Errno::EACCES => e raise Bolt::FileError.new( "#{e.}; unable to create plan", plan_path ) end { name: plan_name, path: plan_path } end |