Class: ImageBuilder::Provisioners::Chef::Base
- Defined in:
- lib/image_builder/provisioners/chef_base.rb
Overview
Generic class doc comment
Constant Summary
Constants included from ImageBuilder
Instance Attribute Summary collapse
-
#chef_version ⇒ Object
Returns the value of attribute chef_version.
-
#config_template ⇒ Object
Returns the value of attribute config_template.
-
#cookbook_paths ⇒ Object
Returns the value of attribute cookbook_paths.
-
#encrypted_data_bag_secret_path ⇒ Object
Returns the value of attribute encrypted_data_bag_secret_path.
-
#execute_command ⇒ Object
Returns the value of attribute execute_command.
-
#install_command ⇒ Object
Returns the value of attribute install_command.
-
#json ⇒ Object
Returns the value of attribute json.
-
#prevent_sudo ⇒ Object
Returns the value of attribute prevent_sudo.
-
#run_list ⇒ Object
Returns the value of attribute run_list.
-
#skip_install ⇒ Object
Returns the value of attribute skip_install.
-
#staging_directory ⇒ Object
Returns the value of attribute staging_directory.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_file(path) ⇒ Object
set attributes from something that looks like a knife.rb file.
Instance Method Summary collapse
-
#cookbook_path(path) ⇒ Object
While not used explicitly in the chef-client provisioner, this will give us consistent behavior across chef provisioners if we need to do a local cookbook lookup.
-
#encrypted_data_bag_secret(sec) ⇒ Object
Map knife.rb config options to their corresponding object attributes the :encrypted_data_bag_secret_path attribute is specific to the chef-solo provisioner, but we’ll need it for all chef provisioners, since we need to upload it to the node before provisioning via the chef-client provisioner.
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #packer_hash ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
24 25 26 27 28 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 24 def initialize @prevent_sudo = false @skip_install = false @encrypted_data_bag_secret_path = ENV['ENCRYPTED_DATA_BAG_SECRET'] end |
Instance Attribute Details
#chef_version ⇒ Object
Returns the value of attribute chef_version.
10 11 12 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 10 def chef_version @chef_version end |
#config_template ⇒ Object
Returns the value of attribute config_template.
12 13 14 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 12 def config_template @config_template end |
#cookbook_paths ⇒ Object
Returns the value of attribute cookbook_paths.
11 12 13 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 11 def cookbook_paths @cookbook_paths end |
#encrypted_data_bag_secret_path ⇒ Object
Returns the value of attribute encrypted_data_bag_secret_path.
13 14 15 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 13 def encrypted_data_bag_secret_path @encrypted_data_bag_secret_path end |
#execute_command ⇒ Object
Returns the value of attribute execute_command.
14 15 16 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 14 def execute_command @execute_command end |
#install_command ⇒ Object
Returns the value of attribute install_command.
15 16 17 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 15 def install_command @install_command end |
#json ⇒ Object
Returns the value of attribute json.
16 17 18 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 16 def json @json end |
#prevent_sudo ⇒ Object
Returns the value of attribute prevent_sudo.
17 18 19 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 17 def prevent_sudo @prevent_sudo end |
#run_list ⇒ Object
Returns the value of attribute run_list.
18 19 20 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 18 def run_list @run_list end |
#skip_install ⇒ Object
Returns the value of attribute skip_install.
19 20 21 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 19 def skip_install @skip_install end |
#staging_directory ⇒ Object
Returns the value of attribute staging_directory.
20 21 22 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 20 def staging_directory @staging_directory end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 22 def type @type end |
Class Method Details
.from_file(path) ⇒ Object
set attributes from something that looks like a knife.rb file
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 31 def self.from_file(path) inst = new @knife_file = ::File.(path) # For knife hash params in knife.rb knife = {} # rubocop:disable Lint/UselessAssignment inst.instance_eval(IO.read(@knife_file)) inst end |
Instance Method Details
#cookbook_path(path) ⇒ Object
While not used explicitly in the chef-client provisioner, this will give us consistent behavior across chef provisioners if we need to do a local cookbook lookup
53 54 55 56 57 58 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 53 def cookbook_path(path) @cookbook_paths = [ENV['COOKBOOK_PATH']] << path @cookbook_paths.flatten! @cookbook_paths.compact! @cookbook_paths.uniq! end |
#encrypted_data_bag_secret(sec) ⇒ Object
Map knife.rb config options to their corresponding object attributes the :encrypted_data_bag_secret_path attribute is specific to the chef-solo provisioner, but we’ll need it for all chef provisioners, since we need to upload it to the node before provisioning via the chef-client provisioner
46 47 48 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 46 def encrypted_data_bag_secret(sec) @encrypted_data_bag_secret_path = sec end |
#packer_hash ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/image_builder/provisioners/chef_base.rb', line 60 def packer_hash hash = { type: @type } unless @chef_version.nil? && @install_command.nil? @install_command = 'curl -L https://www.opscode.com/chef/install.sh | ' @install_command += 'sudo ' unless @prevent_sudo @install_command += 'bash -s -- -v ' + @chef_version end attr_to_hash(hash, :config_template) attr_to_hash(hash, :execute_command) attr_to_hash(hash, :install_command) attr_to_hash(hash, :json) attr_to_hash(hash, :prevent_sudo) attr_to_hash(hash, :run_list) attr_to_hash(hash, :skip_install) attr_to_hash(hash, :staging_directory) hash end |