Class: VagrantPlugins::VagrantHyperV::Provisioner::ChefSolo
- Inherits:
-
Object
- Object
- VagrantPlugins::VagrantHyperV::Provisioner::ChefSolo
- Defined in:
- lib/vagrant-windows-hyperv/provisioner/chef_solo.rb
Instance Attribute Summary collapse
-
#provisioner ⇒ Object
readonly
Returns the value of attribute provisioner.
Instance Method Summary collapse
-
#chef_binary_path(binary) ⇒ Object
Returns the path to the Chef binary, taking into account the ‘binary_path` configuration option.
- #config ⇒ Object
- #copy_folder_to_guest(folders) ⇒ Object
- #delete_encrypted_data_bag_secret ⇒ Object
- #encrypted_data_bag_secret_key_path ⇒ Object
- #guest_paths(folders) ⇒ Object
-
#initialize(env) ⇒ ChefSolo
constructor
A new instance of ChefSolo.
- #provision_for_windows ⇒ Object
- #run_chef_solo ⇒ Object
- #setup_config(template, filename, template_vars) ⇒ Object
- #setup_json ⇒ Object
- #setup_solo_config ⇒ Object
- #upload_encrypted_data_bag_secret ⇒ Object
Constructor Details
permalink #initialize(env) ⇒ ChefSolo
Returns a new instance of ChefSolo.
14 15 16 17 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 14 def initialize(env) @env = env @provisioner = env[:provisioner] end |
Instance Attribute Details
permalink #provisioner ⇒ Object (readonly)
Returns the value of attribute provisioner.
13 14 15 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 13 def provisioner @provisioner end |
Instance Method Details
permalink #chef_binary_path(binary) ⇒ Object
Returns the path to the Chef binary, taking into account the ‘binary_path` configuration option.
165 166 167 168 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 165 def chef_binary_path(binary) return binary if !config.binary_path return File.join(config.binary_path, binary) end |
permalink #config ⇒ Object
[View source]
155 156 157 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 155 def config provisioner.config end |
permalink #copy_folder_to_guest(folders) ⇒ Object
[View source]
170 171 172 173 174 175 176 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 170 def copy_folder_to_guest(folders) folders.each do |type, local_path, remote_path| if type == :host @env[:machine].provider.driver.upload(local_path, remote_path) end end end |
permalink #delete_encrypted_data_bag_secret ⇒ Object
[View source]
140 141 142 143 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 140 def delete_encrypted_data_bag_secret # Run remote command to delete # config.encrypted_data_bag_secret end |
permalink #encrypted_data_bag_secret_key_path ⇒ Object
[View source]
151 152 153 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 151 def encrypted_data_bag_secret_key_path File.(config.encrypted_data_bag_secret_key_path, @env[:machine].env.root_path) end |
permalink #guest_paths(folders) ⇒ Object
[View source]
159 160 161 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 159 def guest_paths(folders) folders.map { |parts| parts[2] } end |
permalink #provision_for_windows ⇒ Object
[View source]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 19 def provision_for_windows # TODO # Verify that the proper shared folders exist. # Copy the chef cookbooks roles data bags and environment folders to Guest copy_folder_to_guest(provisioner.cookbook_folders) copy_folder_to_guest(provisioner.role_folders) copy_folder_to_guest(provisioner.data_bags_folders) copy_folder_to_guest(provisioner.environments_folders) # Upload Encrypted data bag upload_encrypted_data_bag_secret if config.encrypted_data_bag_secret_key_path setup_json setup_solo_config run_chef_solo delete_encrypted_data_bag_secret end |
permalink #run_chef_solo ⇒ Object
[View source]
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 109 def run_chef_solo if config.run_list && config.run_list.empty? @env[:machine].ui.warn(I18n.t("vagrant.chef_run_list_empty")) end = [ "-c #{config.provisioning_path}/solo.rb", "-j #{config.provisioning_path}/dna.json" ] command_env = config.binary_env ? "#{config.binary_env} " : "" command_args = config.arguments ? " #{config.arguments}" : "" command = "#{command_env}#{chef_binary_path("chef-solo")} " + "#{.join(" ")} #{command_args}" config.attempts.times do |attempt| if attempt == 0 @env[:machine].env.ui.info I18n.t("vagrant.provisioners.chef.running_solo") else @env[:machine].env.ui.info I18n.t("vagrant.provisioners.chef.running_solo_again") end @env[:machine].provider.driver.run_remote_ps(command) do |type, data| # Output the data with the proper color based on the stream. if (type == :stdout || type == :stderr) @env[:ui].detail data end end end end |
permalink #setup_config(template, filename, template_vars) ⇒ Object
[View source]
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 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 71 def setup_config(template, filename, template_vars) # If we have custom configuration, upload it remote_custom_config_path = nil if config.custom_config_path = File.( config.custom_config_path, @machine.env.root_path) remote_custom_config_path = File.join( config.provisioning_path, "custom-config.rb") @env[:machine].provider.driver.upload(, remote_custom_config_path) end config_file = Vagrant::Util::TemplateRenderer.render(template, { :custom_configuration => remote_custom_config_path, :file_cache_path => config.file_cache_path, :file_backup_path => config.file_backup_path, :log_level => config.log_level.to_sym, :verbose_logging => config.verbose_logging, :http_proxy => config.http_proxy, :http_proxy_user => config.http_proxy_user, :http_proxy_pass => config.http_proxy_pass, :https_proxy => config.https_proxy, :https_proxy_user => config.https_proxy_user, :https_proxy_pass => config.https_proxy_pass, :no_proxy => config.no_proxy, :formatter => config.formatter }.merge(template_vars)) # Create a temporary file to store the data so we # can upload it temp = Tempfile.new("vagrant") temp.write(config_file) temp.close remote_file = File.join(config.provisioning_path, filename) @env[:machine].provider.driver.upload(temp.path, remote_file) end |
permalink #setup_json ⇒ Object
[View source]
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 37 def setup_json @env[:machine].env.ui.info I18n.t("vagrant.provisioners.chef.json") # Get the JSON that we're going to expose to Chef json = config.json json[:run_list] = config.run_list if !config.run_list.empty? json = JSON.pretty_generate(json) # Create a temporary file to store the data so we # can upload it temp = Tempfile.new("vagrant") temp.write(json) temp.close remote_file = File.join(config.provisioning_path, "dna.json") @env[:machine].provider.driver.upload(temp.path, remote_file) end |
permalink #setup_solo_config ⇒ Object
[View source]
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 55 def setup_solo_config cookbooks_path = guest_paths(provisioner.cookbook_folders) roles_path = guest_paths(provisioner.role_folders) data_bags_path = guest_paths(provisioner.data_bags_folders).first environments_path = guest_paths(provisioner.environments_folders).first source_path = "#{VagrantPlugins::VagrantHyperV.source_root}" template_path = source_path + "/templates/provisioners/chef-solo/solo" setup_config(template_path, "solo.rb", { :cookbooks_path => cookbooks_path, :recipe_url => config.recipe_url, :roles_path => roles_path, :data_bags_path => data_bags_path, :environments_path => environments_path }) end |
permalink #upload_encrypted_data_bag_secret ⇒ Object
[View source]
145 146 147 148 149 |
# File 'lib/vagrant-windows-hyperv/provisioner/chef_solo.rb', line 145 def upload_encrypted_data_bag_secret @machine.env.ui.info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key") @env[:machine].provider.driver.upload(encrypted_data_bag_secret_key_path, config.encrypted_data_bag_secret) end |