diff --git a/doc/dynamic-environments/configuration.mkd b/doc/dynamic-environments/configuration.mkd index 05bcc2744..5527f0f0d 100644 --- a/doc/dynamic-environments/configuration.mkd +++ b/doc/dynamic-environments/configuration.mkd @@ -327,6 +327,15 @@ deploy: puppet_path: '/usr/local/bin/puppet' ``` +#### puppet\_conf + +The path to the puppet.conf file used for generating types. Defaults to `/etc/puppetlabs/puppet/puppet.conf`. + +```yaml +deploy: + puppet_conf: '/opt/puppet/conf/puppet.conf' +``` + Source options -------------- diff --git a/lib/r10k/action/deploy/environment.rb b/lib/r10k/action/deploy/environment.rb index 92423bf54..8bb3ec79e 100644 --- a/lib/r10k/action/deploy/environment.rb +++ b/lib/r10k/action/deploy/environment.rb @@ -184,6 +184,7 @@ def allowed_initialize_opts 'no-force': :self, 'generate-types': :self, 'puppet-path': :self, + 'puppet-conf': :self, 'default-branch-override': :self) end end diff --git a/lib/r10k/action/deploy/module.rb b/lib/r10k/action/deploy/module.rb index ff2b8a4d4..02a01e2c0 100644 --- a/lib/r10k/action/deploy/module.rb +++ b/lib/r10k/action/deploy/module.rb @@ -72,7 +72,7 @@ def visit_module(mod) end def allowed_initialize_opts - super.merge(environment: true, 'no-force': :self, 'generate-types': :self, 'puppet-path': :self) + super.merge(environment: true, 'no-force': :self, 'generate-types': :self, 'puppet-path': :self, 'puppet-conf': :self) end end end diff --git a/lib/r10k/action/runner.rb b/lib/r10k/action/runner.rb index 5de300edf..b5f9148ca 100644 --- a/lib/r10k/action/runner.rb +++ b/lib/r10k/action/runner.rb @@ -46,6 +46,7 @@ def setup_settings overrides[:cachedir] = @opts[:cachedir] unless @opts[:cachedir].nil? overrides[:deploy] = {} if @opts[:'puppet-path'] || @opts[:'generate-types'] overrides[:deploy][:puppet_path] = @opts[:'puppet-path'] unless @opts[:'puppet-path'].nil? + overrides[:deploy][:puppet_conf] = @opts[:'puppet-conf'] unless @opts[:'puppet-conf'].nil? overrides[:deploy][:generate_types] = @opts[:'generate-types'] unless @opts[:'generate-types'].nil? with_overrides = config_settings.merge(overrides) do |key, oldval, newval| diff --git a/lib/r10k/cli/deploy.rb b/lib/r10k/cli/deploy.rb index fbde98488..0685a802b 100644 --- a/lib/r10k/cli/deploy.rb +++ b/lib/r10k/cli/deploy.rb @@ -31,6 +31,13 @@ def self.command exit 1 end end + option nil, :'puppet-conf', 'Path to puppet.conf', argument: :required do |value, cmd| + unless File.exist? value + $stderr.puts "The specified puppet.conf #{value} does not exist." + puts cmd.help + exit 1 + end + end run do |opts, args, cmd| puts cmd.help(:verbose => opts[:verbose]) diff --git a/lib/r10k/environment/base.rb b/lib/r10k/environment/base.rb index 51f62b584..cfdd2cd43 100644 --- a/lib/r10k/environment/base.rb +++ b/lib/r10k/environment/base.rb @@ -137,7 +137,7 @@ def purge_exclusions end def generate_types! - argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir] + argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir, '--config', R10K::Settings.puppet_conf] subproc = R10K::Util::Subprocess.new(argv) subproc.raise_on_fail = true subproc.logger = logger diff --git a/lib/r10k/initializers.rb b/lib/r10k/initializers.rb index 5beb234f3..a4004ec9a 100644 --- a/lib/r10k/initializers.rb +++ b/lib/r10k/initializers.rb @@ -44,6 +44,7 @@ def call class DeployInitializer < BaseInitializer def call with_setting(:puppet_path) { |value| R10K::Settings.puppet_path = value } + with_setting(:puppet_conf) { |value| R10K::Settings.puppet_conf = value } end end diff --git a/lib/r10k/settings.rb b/lib/r10k/settings.rb index 20333dc62..4a869c07a 100644 --- a/lib/r10k/settings.rb +++ b/lib/r10k/settings.rb @@ -12,6 +12,8 @@ module Settings class << self # Path to puppet executable attr_accessor :puppet_path + # Path to puppet.conf + attr_accessor :puppet_conf end def self.git_settings @@ -131,6 +133,15 @@ def self.deploy_settings end end }), + Definition.new(:puppet_conf, { + :desc => "Path to puppet.conf. Defaults to /etc/puppetlabs/puppet/puppet.conf.", + :default => '/etc/puppetlabs/puppet/puppet.conf', + :validate => lambda do |value| + unless File.exist? value + raise ArgumentError, "The specified puppet.conf #{value} does not exist" + end + end + }), ]) end diff --git a/spec/unit/action/deploy/environment_spec.rb b/spec/unit/action/deploy/environment_spec.rb index a733e1ef8..165950306 100644 --- a/spec/unit/action/deploy/environment_spec.rb +++ b/spec/unit/action/deploy/environment_spec.rb @@ -331,6 +331,15 @@ expect(subject.instance_variable_get(:@puppet_path)).to eq('/nonexistent') end end + + describe 'with puppet-conf' do + + subject { described_class.new({ config: '/some/nonexistent/path', 'puppet-conf': '/nonexistent' }, []) } + + it 'sets puppet_conf' do + expect(subject.instance_variable_get(:@puppet_conf)).to eq('/nonexistent') + end + end end describe "write_environment_info!" do diff --git a/spec/unit/action/deploy/module_spec.rb b/spec/unit/action/deploy/module_spec.rb index daa719828..6fe057ebe 100644 --- a/spec/unit/action/deploy/module_spec.rb +++ b/spec/unit/action/deploy/module_spec.rb @@ -25,6 +25,10 @@ it 'can accept a puppet-path option' do described_class.new({ 'puppet-path': '/nonexistent' }, []) end + + it 'can accept a puppet-conf option' do + described_class.new({ 'puppet-conf': '/nonexistent' }, []) + end end describe "with no-force" do @@ -123,4 +127,13 @@ expect(subject.instance_variable_get(:@puppet_path)).to eq('/nonexistent') end end + + describe 'with puppet-conf' do + + subject { described_class.new({ config: '/some/nonexistent/path', 'puppet-conf': '/nonexistent' }, []) } + + it 'sets puppet_conf' do + expect(subject.instance_variable_get(:@puppet_conf)).to eq('/nonexistent') + end + end end diff --git a/spec/unit/settings_spec.rb b/spec/unit/settings_spec.rb index 9048c8edd..9ce373ddb 100644 --- a/spec/unit/settings_spec.rb +++ b/spec/unit/settings_spec.rb @@ -129,6 +129,18 @@ expect { subject.evaluate('puppet_path' => '/nonexistent') }.to raise_error(R10K::Settings::Collection::ValidationError) end end + + describe 'puppet_conf' do + it 'when file raises no error' do + expect(File).to receive(:exist?).with('/nonexistent').and_return(true) + expect { subject.evaluate('puppet_conf' => '/nonexistent') }.not_to raise_error + end + + it 'when not file raises error' do + expect(File).to receive(:exist?).with('/nonexistent') + expect { subject.evaluate('puppet_conf' => '/nonexistent') }.to raise_error(R10K::Settings::Collection::ValidationError) + end + end end describe "global settings" do