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

[WIP] Refactor classes postrun_command, prerun_command #488

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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,326 changes: 1,326 additions & 0 deletions REFERENCE.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
r10k::include_postrun_command: false
r10k::postrun_command::ensure: 'present'
r10k::postrun_command::command: 'deploy environment -p'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r10k is showing -p is deprecated, and suggests use of -m


r10k::include_prerun_command: false
r10k::prerun_command::ensure: 'present'
r10k::prerun_command::command: 'deploy environment -p'
16 changes: 16 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: 5

defaults:
datadir: 'data'
data_hash: 'yaml_data'

hierarchy:
- name: 'Major Version'
path: "os/%{facts.os.name}-%{facts.os.release.major}.yaml"
- name: 'Distribution Name'
path: "os/%{facts.os.name}.yaml"
- name: 'Operating System Family'
path: "family/%{facts.os.family}.yaml"
- name: 'Common'
path: 'common.yaml'
5 changes: 0 additions & 5 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
}
$r10k_cache_dir = "${facts['puppet_vardir']}/r10k"
$r10k_config_file = '/etc/puppetlabs/r10k/r10k.yaml'
$r10k_binary = 'r10k'
$puppetconf_path = '/etc/puppetlabs/puppet'
$manage_configfile_symlink = false
$configfile_symlink = '/etc/r10k.yaml'
Expand Down Expand Up @@ -109,10 +108,6 @@
fail("Puppet version ${facts['puppetversion']} is no longer supported. Please use an earlier version of puppet/r10k.")
}

# prerun_command in puppet.conf
$pre_postrun_command = "${r10k_binary} deploy environment -p"


# Mcollective configuration static
$mc_agent_name = "${module_name}.rb"
$mc_agent_ddl_name = "${module_name}.ddl"
Expand Down
20 changes: 15 additions & 5 deletions manifests/postrun_command.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# This class will configure r10k to run as part of the masters agent run
# @summary
# This class handles the R10k postrun command.
#
# @param ensure
# Whether to configure the R10k postrun command.
#
# @param command
# Specifies a command to run after every agent run.
#
class r10k::postrun_command (
$command = $r10k::params::pre_postrun_command,
Enum['present', 'absent'] $ensure = 'present',
) inherits r10k::params {
String[1] $command = 'deploy environment -p',
) {

$binary = pick_default($facts['r10k_path'], '/bin/r10k')

ini_setting { 'r10k_postrun_command':
ensure => $ensure,
path => "${r10k::params::puppetconf_path}/puppet.conf",
path => $settings::config,
section => 'agent',
setting => 'postrun_command',
value => $command,
value => "${binary} ${command}",
}
}
20 changes: 15 additions & 5 deletions manifests/prerun_command.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# This class will configure r10k to run as part of the masters agent run
# @summary
# This class handles the R10k prerun command.
#
# @param ensure
# Whether to configure the R10k prerun command.
#
# @param command
# Specifies a command to run before every agent run.
#
class r10k::prerun_command (
$command = $r10k::params::pre_postrun_command,
Enum['present', 'absent'] $ensure = 'present',
) inherits r10k::params {
String[1] $command = 'deploy environment -p',
) {

$binary = pick_default($facts['r10k_path'], '/bin/r10k')

ini_setting { 'r10k_prerun_command':
ensure => $ensure,
path => "${r10k::params::puppetconf_path}/puppet.conf",
path => $settings::config,
section => 'agent',
setting => 'prerun_command',
value => $command,
value => "${binary} ${command}",
}
}
23 changes: 9 additions & 14 deletions spec/classes/postrun_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,89 +16,84 @@
context 'adding custom postrun_command' do
let :params do
{
command: 'r10k synchronize',
command: 'synchronize',
ensure: 'present'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_postrun_command').with(
ensure: 'present',
section: 'agent',
setting: 'postrun_command',
value: 'r10k synchronize'
value: '/bin/r10k synchronize'
)
end
end

context 'removing custom postrun_command' do
let :params do
{
command: 'r10k synchronize',
command: 'synchronize',
ensure: 'absent'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_postrun_command').with(
ensure: 'absent',
section: 'agent',
setting: 'postrun_command',
value: 'r10k synchronize'
value: '/bin/r10k synchronize'
)
end
end
end

context 'with Puppet FOSS' do
context 'adding default postrun_command' do
it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_postrun_command').with(
ensure: 'present',
section: 'agent',
setting: 'postrun_command',
value: 'r10k deploy environment -p'
value: '/bin/r10k deploy environment -p'
)
end
end

context 'adding custom postrun_command' do
let :params do
{
command: 'r10k21 synchronize',
command: 'synchronize',
ensure: 'present'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_postrun_command').with(
ensure: 'present',
section: 'agent',
setting: 'postrun_command',
value: 'r10k21 synchronize'
value: '/bin/r10k synchronize'
)
end
end

context 'removing custom postrun_command' do
let :params do
{
command: 'r10k21 synchronize',
command: 'synchronize',
ensure: 'absent'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_postrun_command').with(
ensure: 'absent',
section: 'agent',
setting: 'postrun_command',
value: 'r10k21 synchronize'
value: '/bin/r10k synchronize'
)
end
end
Expand Down
42 changes: 9 additions & 33 deletions spec/classes/prerun_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,112 +16,88 @@
context 'adding custom prerun_command' do
let :params do
{
command: 'r10k synchronize',
command: 'synchronize',
ensure: 'present'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_prerun_command').with(
ensure: 'present',
section: 'agent',
setting: 'prerun_command',
value: 'r10k synchronize'
value: '/bin/r10k synchronize'
)
end
end

context 'removing custom prerun_command' do
let :params do
{
command: 'r10k synchronize',
command: 'synchronize',
ensure: 'absent'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_prerun_command').with(
ensure: 'absent',
section: 'agent',
setting: 'prerun_command',
value: 'r10k synchronize'
value: '/bin/r10k synchronize'
)
end
end
end

context 'with Puppet FOSS' do
context 'default prerun_command' do
it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_prerun_command').with(
ensure: 'present',
section: 'agent',
setting: 'prerun_command',
value: 'r10k deploy environment -p'
value: '/bin/r10k deploy environment -p'
)
end
end

context 'adding custom prerun_command' do
let :params do
{
command: 'r10k21 synchronize',
command: 'synchronize',
ensure: 'present'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_prerun_command').with(
ensure: 'present',
section: 'agent',
setting: 'prerun_command',
value: 'r10k21 synchronize'
value: '/bin/r10k synchronize'
)
end
end

context 'removing custom prerun_command' do
let :params do
{
command: 'r10k21 synchronize',
command: 'synchronize',
ensure: 'absent'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_prerun_command').with(
ensure: 'absent',
section: 'agent',
setting: 'prerun_command',
value: 'r10k21 synchronize'
value: '/bin/r10k synchronize'
)
end
end
end

context 'removing custom prerun_command' do
let :params do
{
command: 'r10k22 synchronize',
ensure: 'absent'
}
end

it { is_expected.to contain_class('r10k::params') }
it do
is_expected.to contain_ini_setting('r10k_prerun_command').with(
ensure: 'absent',
section: 'agent',
setting: 'prerun_command',
value: 'r10k22 synchronize'
)
end
end
end
end
end