Merge pull request #9670 from briancain/aloyr-puppet_structured_facts_toyaml_on_provisioner

Aloyr puppet structured facts toyaml on provisioner
This commit is contained in:
Brian Cain 2018-04-09 11:23:52 -07:00 committed by GitHub
commit f636c30aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -8,6 +8,7 @@ module VagrantPlugins
attr_accessor :binary_path attr_accessor :binary_path
attr_accessor :facter attr_accessor :facter
attr_accessor :structured_facts
attr_accessor :hiera_config_path attr_accessor :hiera_config_path
attr_accessor :manifest_file attr_accessor :manifest_file
attr_accessor :manifests_path attr_accessor :manifests_path
@ -37,6 +38,7 @@ module VagrantPlugins
@synced_folder_type = UNSET_VALUE @synced_folder_type = UNSET_VALUE
@temp_dir = UNSET_VALUE @temp_dir = UNSET_VALUE
@working_directory = UNSET_VALUE @working_directory = UNSET_VALUE
@structured_facts = UNSET_VALUE
end end
def nfs=(value) def nfs=(value)

View File

@ -132,6 +132,22 @@ module VagrantPlugins
@machine.communicate.upload(local_hiera_path, @hiera_config_path) @machine.communicate.upload(local_hiera_path, @hiera_config_path)
end 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 run_puppet_apply
end end
@ -213,7 +229,8 @@ module VagrantPlugins
# Build up the custom facts if we have any # Build up the custom facts if we have any
facter = nil 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 = [] facts = []
config.facter.each do |key, value| config.facter.each do |key, value|
facts << "FACTER_#{key}='#{value}'" facts << "FACTER_#{key}='#{value}'"

View File

@ -39,6 +39,7 @@ describe VagrantPlugins::Puppet::Provisioner::Puppet do
allow(config).to receive(:environment_variables).and_return(nil) allow(config).to receive(:environment_variables).and_return(nil)
allow(config).to receive(:working_directory).and_return(false) allow(config).to receive(:working_directory).and_return(false)
allow(config).to receive(:manifest_file).and_return(manifest_file) 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_message_expectations_on_nil
allow(@module_paths).to receive(:map) { module_paths } allow(@module_paths).to receive(:map) { module_paths }