Class: VagrantPlugins::WinAzure::Provisioner::ChefSolo
- Inherits:
-
Object
- Object
- VagrantPlugins::WinAzure::Provisioner::ChefSolo
- Defined in:
- lib/vagrant-azure/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
- #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
#initialize(env) ⇒ ChefSolo
Returns a new instance of ChefSolo.
15 16 17 18 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 15 def initialize(env) @env = env @provisioner = env[:provisioner] end |
Instance Attribute Details
#provisioner ⇒ Object (readonly)
Returns the value of attribute provisioner.
13 14 15 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 13 def provisioner @provisioner end |
Instance Method Details
#chef_binary_path(binary) ⇒ Object
Returns the path to the Chef binary, taking into account the ‘binary_path` configuration option.
161 162 163 164 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 161 def chef_binary_path(binary) return binary if !config.binary_path return File.join(config.binary_path, binary) end |
#config ⇒ Object
151 152 153 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 151 def config provisioner.config end |
#copy_folder_to_guest(folders) ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 166 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 |
#encrypted_data_bag_secret_key_path ⇒ Object
147 148 149 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 147 def encrypted_data_bag_secret_key_path File.(config.encrypted_data_bag_secret_key_path, @env[:machine].env.root_path) end |
#guest_paths(folders) ⇒ Object
155 156 157 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 155 def guest_paths(folders) folders.map { |parts| parts[2] } end |
#provision_for_windows ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 20 def provision_for_windows # 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 # TODO # delete_encrypted_data_bag_secret end |
#run_chef_solo ⇒ Object
108 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 139 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 108 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 command @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 |
#setup_config(template, filename, template_vars) ⇒ Object
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 |
# File 'lib/vagrant-azure/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 |
#setup_json ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant-azure/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 |
#setup_solo_config ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vagrant-azure/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::WinAzure.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 |
#upload_encrypted_data_bag_secret ⇒ Object
141 142 143 144 145 |
# File 'lib/vagrant-azure/provisioner/chef-solo.rb', line 141 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 |