From 770d927ba10e68889f8d7e706b84121948dc12fb Mon Sep 17 00:00:00 2001 From: Ben Hines Date: Wed, 15 Jul 2015 00:38:57 -0700 Subject: [PATCH 1/5] Structured yaml facts - first pass --- plugins/provisioners/puppet/config/puppet.rb | 3 +++ .../provisioners/puppet/provisioner/puppet.rb | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 9910c6e05..42815a5f6 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 @@ -32,6 +33,7 @@ module VagrantPlugins @module_path = UNSET_VALUE @options = [] @facter = {} + @structured_facts = UNSET_VALUE @synced_folder_type = UNSET_VALUE @temp_dir = UNSET_VALUE @working_directory = UNSET_VALUE @@ -52,6 +54,7 @@ module VagrantPlugins def merge(other) super.tap do |result| result.facter = @facter.merge(other.facter) + result.structured_facts = @facter.merge(other.structured_facts) result.environment_path = @facter.merge(other.environment_path) result.environment = @facter.merge(other.environment) end diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index e7c598140..d6da79100 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -121,6 +121,19 @@ 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/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) + t.close() + @machine.communicate.upload(t.path, @facter_config_path) + end + run_puppet_apply end @@ -200,9 +213,9 @@ module VagrantPlugins options << @manifest_file options = options.join(" ") - # Build up the custom facts if we have any + # Build up the (non-structured) custom facts if we have any facter = "" - if !config.facter.empty? + if !config.structured_facts && !config.facter.empty? facts = [] config.facter.each do |key, value| facts << "FACTER_#{key}='#{value}'" From bfb66f31666ce10f5f391bbdf70ca57f615a4497 Mon Sep 17 00:00:00 2001 From: Ben Hines Date: Wed, 15 Jul 2015 16:52:00 -0700 Subject: [PATCH 2/5] Correct default path to facter and indentaion --- plugins/provisioners/puppet/provisioner/puppet.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index d6da79100..f14746849 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -124,16 +124,16 @@ module VagrantPlugins # 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/facter/facts.d/vagrant_facts.yaml" + @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) + t.write(config.facter) t.close() @machine.communicate.upload(t.path, @facter_config_path) - end - + end + run_puppet_apply end From 97a9cd35fc86a153360552f637a360767561e99f Mon Sep 17 00:00:00 2001 From: Ben Hines Date: Wed, 15 Jul 2015 17:13:47 -0700 Subject: [PATCH 3/5] Upload facts to temp dir before sudoing them to final location. --- plugins/provisioners/puppet/provisioner/puppet.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index f14746849..cce0d4af8 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -129,11 +129,14 @@ module VagrantPlugins @facter_config_path = "/ProgramData/PuppetLabs/facter/facts.d/vagrant_facts.yaml" end t = Tempfile.new("vagrant_facts.yaml") - t.write(config.facter) + t.write(config.facter) t.close() - @machine.communicate.upload(t.path, @facter_config_path) + @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 From 4d4bba119a12a6d059e0747d0f91a68eaa75e092 Mon Sep 17 00:00:00 2001 From: Ben Hines Date: Tue, 28 Jul 2015 12:20:30 -0700 Subject: [PATCH 4/5] Correct some upstream errors --- plugins/provisioners/puppet/config/puppet.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 42815a5f6..185745675 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -33,7 +33,7 @@ module VagrantPlugins @module_path = UNSET_VALUE @options = [] @facter = {} - @structured_facts = UNSET_VALUE + @structured_facts = UNSET_VALUE @synced_folder_type = UNSET_VALUE @temp_dir = UNSET_VALUE @working_directory = UNSET_VALUE @@ -54,9 +54,6 @@ module VagrantPlugins def merge(other) super.tap do |result| result.facter = @facter.merge(other.facter) - result.structured_facts = @facter.merge(other.structured_facts) - result.environment_path = @facter.merge(other.environment_path) - result.environment = @facter.merge(other.environment) end end @@ -146,7 +143,7 @@ module VagrantPlugins if !expanded_environment_file.file? && !expanded_environment_file.directory? errors << I18n.t("vagrant.provisioners.puppet.environment_missing", environment: environment.to_s, - environment_path: expanded_path.to_s) + environmentpath: expanded_path.to_s) end end end From d5c13dda647e13e44b7850c7f84bab17182d4a8d Mon Sep 17 00:00:00 2001 From: Peter Carrero Date: Wed, 13 Apr 2016 16:11:25 -0500 Subject: [PATCH 5/5] puppet: Add "to_yaml" to facter call The rationale here is to make it so existing Vagrantfile configurations remain unchanged. While benh57's solution worked for me, I had to add a ".to_yaml" to the VagrantFile line that implemented puppet.facter and this would mean existing Vagrant configurations that use Puppet would produce an error if that was not present. Additionally, without this change, the Vagrant file also needed a "require('yaml')" declaration to make the ".to_yaml" conversion possible. --- plugins/provisioners/puppet/provisioner/puppet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index cce0d4af8..28a3d8cf0 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -129,7 +129,7 @@ module VagrantPlugins @facter_config_path = "/ProgramData/PuppetLabs/facter/facts.d/vagrant_facts.yaml" end t = Tempfile.new("vagrant_facts.yaml") - t.write(config.facter) + 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"))