Class: Vagrant::Provisioners::Chef
- Includes:
- Util::Counter
- Defined in:
- lib/vagrant/provisioners/chef.rb,
lib/vagrant/provisioners/chef.rb,
lib/vagrant/provisioners/chef.rb more...
Overview
This class is a base class where the common functionality shared between chef-solo and chef-client provisioning are stored. This is not an actual provisioner. Instead, ChefSolo or ChefServer should be used.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#chef_binary_path(binary) ⇒ Object
Returns the path to the Chef binary, taking into account the
binary_path
configuration option. - #chown_provisioning_folder ⇒ Object
-
#initialize(env, config) ⇒ Chef
constructor
A new instance of Chef.
- #prepare ⇒ Object
- #setup_config(template, filename, template_vars) ⇒ Object
- #setup_json ⇒ Object
- #verify_binary(binary) ⇒ Object
Methods included from Util::Counter
#get_and_update_counter, #mutex
Methods inherited from Base
#cleanup, config_class, #provision!
Constructor Details
permalink #initialize(env, config) ⇒ Chef
Returns a new instance of Chef.
11 12 13 14 15 |
# File 'lib/vagrant/provisioners/chef.rb', line 11 def initialize(env, config) super config.provisioning_path ||= "/tmp/vagrant-chef-#{get_and_update_counter(:provisioning_path)}" 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.
32 33 34 35 |
# File 'lib/vagrant/provisioners/chef.rb', line 32 def chef_binary_path(binary) return binary if !config.binary_path return File.join(config.binary_path, binary) end |
permalink #chown_provisioning_folder ⇒ Object
[View source]
37 38 39 40 |
# File 'lib/vagrant/provisioners/chef.rb', line 37 def chown_provisioning_folder env[:vm].channel.sudo("mkdir -p #{config.provisioning_path}") env[:vm].channel.sudo("chown #{env[:vm].config.ssh.username} #{config.provisioning_path}") end |
permalink #prepare ⇒ Object
17 18 19 |
# File 'lib/vagrant/provisioners/chef.rb', line 17 def prepare raise ChefError, :invalid_provisioner end |
permalink #setup_config(template, filename, template_vars) ⇒ Object
[View source]
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant/provisioners/chef.rb', line 42 def setup_config(template, filename, template_vars) config_file = TemplateRenderer.render(template, { :log_level => config.log_level.to_sym, :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 }.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[:vm].channel.sudo("rm #{remote_file}", :error_check => false) env[:vm].channel.upload(temp.path, remote_file) end |
permalink #setup_json ⇒ Object
[View source]
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 |
# File 'lib/vagrant/provisioners/chef.rb', line 65 def setup_json env[:ui].info I18n.t("vagrant.provisioners.chef.json") # Set up our configuration that is passed to the attributes by default data = { :config => env[:global_config].to_hash } # Add our default share directory if it exists default_share = env[:vm].config.vm.shared_folders["v-root"] data[:directory] = default_share[:guestpath] if default_share # And wrap it under the "vagrant" namespace data = { :vagrant => data } # Merge with the "extra data" which isn't put under the # vagrant namespace by default data.merge!(config.merged_json) json = data.to_json # Create a temporary file to store the data so we # can upload it temp = Tempfile.new("vagrant") temp.write(json) temp.close env[:vm].channel.upload(temp.path, File.join(config.provisioning_path, "dna.json")) end |
permalink #verify_binary(binary) ⇒ Object
[View source]
21 22 23 24 25 26 27 28 |
# File 'lib/vagrant/provisioners/chef.rb', line 21 def verify_binary(binary) # Checks for the existence of chef binary and error if it # doesn't exist. env[:vm].channel.sudo("which #{binary}", :error_class => ChefError, :error_key => :chef_not_detected, :binary => binary) end |