Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for defining custom puppet.conf when generating types #993

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGELOG

Unreleased
----------
- Add support for defining custom puppet.conf when generating types [#993](https://github.com/puppetlabs/r10k/pull/993)
- Update test cases to account for error message changes in Puppet 7

3.6.0
Expand Down
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 @@ -188,6 +188,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
3 changes: 2 additions & 1 deletion lib/r10k/action/deploy/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def allowed_initialize_opts
cachedir: :self,
'no-force': :self,
'generate-types': :self,
'puppet-path': :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] if @opts.key?(:cachedir)
overrides[:deploy] = {} if @opts.key?(:'puppet-path') || @opts.key?(:'generate-types')
overrides[:deploy][:puppet_path] = @opts[:'puppet-path'] if @opts.key?(:'puppet-path')
overrides[:deploy][:puppet_conf] = @opts[:'puppet-conf'] unless @opts[:'puppet-conf'].nil?
overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')

with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
Expand Down
1 change: 1 addition & 0 deletions lib/r10k/cli/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def self.command
exit 1
end
end
option nil, :'puppet-conf', 'Path to puppet.conf', argument: :required

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.readable? value
raise ArgumentError, "The specified puppet.conf #{value} is not readable"
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 @@ -26,6 +26,10 @@
described_class.new({ 'puppet-path': '/nonexistent' }, [])
end

it 'can accept a puppet-conf option' do
described_class.new({ 'puppet-conf': '/nonexistent' }, [])
end

it 'can accept a cachedir option' do
described_class.new({ cachedir: '/nonexistent' }, [])
end
Expand Down Expand Up @@ -128,6 +132,15 @@
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

describe 'with cachedir' do

subject { described_class.new({ config: '/some/nonexistent/path', cachedir: '/nonexistent' }, []) }
Expand Down
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
allow(File).to receive(:readable?).with('/nonexistent').and_return(true)
expect { subject.evaluate('puppet_conf' => '/nonexistent') }.not_to raise_error
end

it 'when not file raises error' do
allow(File).to receive(:readable?).with('/nonexistent').and_return(false)
expect { subject.evaluate('puppet_conf' => '/nonexistent') }.to raise_error(R10K::Settings::Collection::ValidationError)
end
end
end

describe "global settings" do
Expand Down