Class: Vagrant::Puppet::Scp::Provisioner
- Inherits:
-
Object
- Object
- Vagrant::Puppet::Scp::Provisioner
- Defined in:
- lib/vagrant/puppet/scp/provisioner.rb
Instance Method Summary collapse
- #configure(root_config) ⇒ Object
- #create_guest_path ⇒ Object
-
#initialize(machine, config) ⇒ Provisioner
constructor
A new instance of Provisioner.
- #provision ⇒ Object
- #recursive_scp(from, to) ⇒ Object
- #run_puppet_apply ⇒ Object
- #share_manifests ⇒ Object
- #share_modules ⇒ Object
- #verify_binary(binary) ⇒ Object
Constructor Details
#initialize(machine, config) ⇒ Provisioner
Returns a new instance of Provisioner.
11 12 13 14 15 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 11 def initialize(machine, config) super @logger = Log4r::Logger.new('vagrant::provisioners::puppet_scp') end |
Instance Method Details
#configure(root_config) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 17 def configure(root_config) # Calculate the paths we're going to use based on the environment root_path = @machine.env.root_path @expanded_manifests_path = @config.(root_path) @expanded_modules_path = @config.(root_path) @manifest_file = File.join(@config.manifests_guest_path, @config.manifest_file) end |
#create_guest_path ⇒ Object
33 34 35 36 37 38 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 33 def create_guest_path @machine.communicate.tap do |comm| comm.sudo("mkdir -p #{@config.guest_path}") comm.sudo("chown -R #{@machine.ssh_info[:username]} #{@config.guest_path}") end end |
#provision ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 25 def provision create_guest_path share_manifests share_modules verify_binary('puppet') run_puppet_apply end |
#recursive_scp(from, to) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 84 def recursive_scp(from, to) @machine.communicate.tap do |comm| comm.sudo("rm -rf #{to}") comm.sudo("mkdir -p #{to}") comm.sudo("chown #{@machine.ssh_info[:username]} #{to}") end Dir.glob("#{from}/**/*") do |path| to_path = path.gsub(from.to_s, '') # Remove the local cruft if File.directory?(path) @machine.communicate.execute("mkdir -p #{to}#{to_path}") else @machine.communicate.upload(path, "#{to}#{to_path}") end end end |
#run_puppet_apply ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 56 def run_puppet_apply = [config.].flatten << "--modulepath '#{@config.modules_guest_path}'" if !@config.modules_guest_path.empty? << @manifest_file = .join(" ") # Build up the custom facts if we have any facter = "" if !config.facter.empty? facts = [] config.facter.each do |key, value| facts << "FACTER_#{key}='#{value}'" end facter = "#{facts.join(" ")} " end command = "#{facter}puppet apply #{} || [ $? -eq 2 ]" @machine.env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => @config.manifest_file) @machine.communicate.sudo(command) do |type, data| data.chomp! @machine.env.ui.info(data, :prefix => false) if !data.empty? end end |
#share_manifests ⇒ Object
40 41 42 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 40 def share_manifests recursive_scp(@expanded_manifests_path, @config.manifests_guest_path) end |
#share_modules ⇒ Object
44 45 46 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 44 def share_modules recursive_scp(@expanded_modules_path, @config.modules_guest_path) end |
#verify_binary(binary) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/vagrant/puppet/scp/provisioner.rb', line 48 def verify_binary(binary) @machine.communicate.sudo( "which #{binary}", :error_class => PuppetScpError, :error_key => :not_detected, :binary => binary) end |