Skip to content

Commit

Permalink
Add support for defining custom puppet.conf when generating types
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Oct 31, 2019
1 parent bd224fc commit 679f82d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doc/dynamic-environments/configuration.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down
1 change: 1 addition & 0 deletions lib/r10k/action/deploy/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/r10k/action/deploy/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/r10k/action/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
7 changes: 7 additions & 0 deletions lib/r10k/cli/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion lib/r10k/environment/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/r10k/initializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions lib/r10k/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions spec/unit/action/deploy/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/action/deploy/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions spec/unit/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 679f82d

Please sign in to comment.