diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 568de5fdb..b261374fa 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -8,6 +8,7 @@ module VagrantPlugins attr_accessor :binary_path attr_accessor :facter + attr_accessor :structured_facts attr_accessor :hiera_config_path attr_accessor :manifest_file attr_accessor :manifests_path @@ -37,6 +38,7 @@ module VagrantPlugins @synced_folder_type = UNSET_VALUE @temp_dir = UNSET_VALUE @working_directory = UNSET_VALUE + @structured_facts = UNSET_VALUE end def nfs=(value) diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index 1b8daf1f5..ae3e6eecc 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -132,6 +132,22 @@ module VagrantPlugins @machine.communicate.upload(local_hiera_path, @hiera_config_path) end + # Build up the structured custom facts if we have any + # With structured facts on, we assume the config.facter is yaml. + if config.structured_facts && !config.facter.empty? + @facter_config_path = "/etc/puppetlabs/facter/facts.d/vagrant_facts.yaml" + if windows? + @facter_config_path = "/ProgramData/PuppetLabs/facter/facts.d/vagrant_facts.yaml" + end + t = Tempfile.new("vagrant_facts.yaml") + t.write(config.facter.to_yaml) + t.close() + @machine.communicate.tap do |comm| + comm.upload(t.path, File.join(@config.temp_dir, "vagrant_facts.yaml")) + comm.sudo("cp #{config.temp_dir}/vagrant_facts.yaml #{@facter_config_path}") + end + end + run_puppet_apply end @@ -213,7 +229,8 @@ module VagrantPlugins # Build up the custom facts if we have any facter = nil - if !config.facter.empty? + # Build up the (non-structured) custom facts if we have any + if !config.structured_facts && !config.facter.empty? facts = [] config.facter.each do |key, value| facts << "FACTER_#{key}='#{value}'" diff --git a/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb b/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb index 01a66eb1b..be1d1fcd4 100644 --- a/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb +++ b/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb @@ -39,6 +39,7 @@ describe VagrantPlugins::Puppet::Provisioner::Puppet do allow(config).to receive(:environment_variables).and_return(nil) allow(config).to receive(:working_directory).and_return(false) allow(config).to receive(:manifest_file).and_return(manifest_file) + allow(config).to receive(:structured_facts).and_return(double("structured_facts")) allow_message_expectations_on_nil allow(@module_paths).to receive(:map) { module_paths }