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 ability to specify a symlink for r10k.yaml #41

Merged
merged 3 commits into from
Jun 2, 2014
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env:
- PUPPET_VERSION="~> 3.2.0"
- PUPPET_VERSION="~> 3.3.0"
- PUPPET_VERSION="~> 3.4.0"
- PUPPET_VERSION="~> 3.5.1"
global:
- PUBLISHER_LOGIN=acidprime
matrix:
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ class { 'r10k':

This will configure `/etc/r10k.yaml` and install the r10k gem after installing
ruby using the [puppetlabs/ruby](http://forge.puppetlabs.com/puppetlabs/ruby) module. It also has a few helper classes that do
some useful things. The following will add a `prerun_command` to puppet.conf.
some useful things. The following entry in Hiera will add a `prerun_command` to puppet.conf.

```puppet
include r10k::prerun_command
```
r10k::include_prerun_command: true
```

The concept here is that this is declared on the puppet master(s) that have
been configured with r10k. This will cause r10k to synchronize before each
puppet run. Any errors synchronizing will be logged to the standard puppet run.

## symlink to r10k.yaml
These entries in Hiera will create a symlink at `/etc/r10k.yaml` that points to the config file at `/etc/puppet/r10k.yaml`

```
r10k::configfile: /etc/puppet/r10k.yaml
r10k::manage_configfile_symlink: true
r10k::configfile_symlink: /etc/r10k.yaml
```

### Mcollective Support

![alt tag](https://gist.github.com/acidprime/7013041/raw/6748f6173b406c03067884199174ce1df313ad58/post_recieve_overview.png)
Expand Down
38 changes: 31 additions & 7 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
# * [*purgedirs*]
# An Array of directory paths to purge of any subdirectories that do not
# correspond to a dynamic environment managed by r10k. Default: []
# * [*manage_configfile_symlink*]
# Boolean to determine if a symlink to the r10k config file is to be managed.
# Default: false
# * [*configfile_symlink*]
# Location of symlink that points to configfile. Default: /etc/r10k.yaml
#
# === Examples
#
Expand Down Expand Up @@ -45,16 +50,27 @@
$configfile,
$cachedir,
$manage_modulepath,
$modulepath = undef,
$remote = '',
$sources = 'UNSET',
$purgedirs = [],
$puppetconf_path = $r10k::params::puppetconf_path,
$r10k_basedir = $r10k::params::r10k_basedir,
$modulepath = undef,
$remote = '',
$sources = 'UNSET',
$purgedirs = [],
$puppetconf_path = $r10k::params::puppetconf_path,
$r10k_basedir = $r10k::params::r10k_basedir,
$manage_configfile_symlink = $r10k::params::manage_configfile_symlink,
$configfile_symlink = '/etc/r10k.yaml',
) inherits r10k::params {

validate_bool($manage_modulepath)

if type($manage_configfile_symlink) == 'string' {
$manage_configfile_symlink_real = str2bool($manage_configfile_symlink)
} else {
$manage_configfile_symlink_real = $manage_configfile_symlink
}
validate_bool($manage_configfile_symlink_real)

validate_absolute_path($configfile_symlink)

if $sources == 'UNSET' {
$r10k_sources = {
'puppet' => {
Expand All @@ -74,7 +90,15 @@
group => '0',
mode => '0644',
path => $configfile,
content => template("${module_name}/${configfile}.erb"),
content => template('r10k/r10k.yaml.erb'),
}

if $manage_configfile_symlink_real == true {
file { 'symlink_r10k.yaml':
ensure => 'link',
path => $configfile_symlink,
target => $configfile,
}
}

if $manage_modulepath {
Expand Down
60 changes: 38 additions & 22 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
# This class configures r10k
class r10k (
$remote = $r10k::params::remote,
$sources = $r10k::params::sources,
$purgedirs = $r10k::params::r10k_purgedirs,
$cachedir = $r10k::params::r10k_cache_dir,
$configfile = $r10k::params::r10k_config_file,
$version = $r10k::params::version,
$modulepath = $r10k::params::modulepath,
$manage_modulepath = $r10k::params::manage_modulepath,
$r10k_basedir = $r10k::params::r10k_basedir,
$package_name = $r10k::params::package_name,
$provider = $r10k::params::provider,
$gentoo_keywords = $r10k::params::gentoo_keywords,
$install_options = $r10k::params::install_options,
$mcollective = $r10k::params::mcollective,
$remote = $r10k::params::remote,
$sources = $r10k::params::sources,
$purgedirs = $r10k::params::r10k_purgedirs,
$cachedir = $r10k::params::r10k_cache_dir,
$configfile = $r10k::params::r10k_config_file,
$version = $r10k::params::version,
$modulepath = $r10k::params::modulepath,
$manage_modulepath = $r10k::params::manage_modulepath,
$r10k_basedir = $r10k::params::r10k_basedir,
$package_name = $r10k::params::package_name,
$provider = $r10k::params::provider,
$gentoo_keywords = $r10k::params::gentoo_keywords,
$install_options = $r10k::params::install_options,
$mcollective = $r10k::params::mcollective,
$manage_configfile_symlink = $r10k::params::manage_configfile_symlink,
$configfile_symlink = $r10k::params::configfile_symlink,
$include_prerun_command = false,
) inherits r10k::params {

if type($include_prerun_command) == 'string' {
$include_prerun_command_real = str2bool($include_prerun_command)
} else {
$include_prerun_command_real = $include_prerun_command
}
validate_bool($include_prerun_command_real)

if $include_prerun_command_real == true {
include r10k::prerun_command
}

class { 'r10k::install':
package_name => $package_name,
version => $version,
Expand All @@ -25,14 +39,16 @@
}

class { 'r10k::config':
cachedir => $cachedir,
configfile => $configfile,
sources => $sources,
purgedirs => $purgedirs,
modulepath => $modulepath,
remote => $remote,
manage_modulepath => $manage_modulepath,
r10k_basedir => $r10k_basedir,
cachedir => $cachedir,
configfile => $configfile,
sources => $sources,
purgedirs => $purgedirs,
modulepath => $modulepath,
remote => $remote,
manage_modulepath => $manage_modulepath,
r10k_basedir => $r10k_basedir,
manage_configfile_symlink => $manage_configfile_symlink,
configfile_symlink => $configfile_symlink,
}

if $mcollective {
Expand Down
10 changes: 6 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
$sources = undef

# r10k configuration
$r10k_config_file = '/etc/r10k.yaml'
$r10k_cache_dir = '/var/cache/r10k'
$r10k_basedir = "${::settings::confdir}/environments"
$r10k_purgedirs = $r10k_basedir
$r10k_config_file = '/etc/r10k.yaml'
$r10k_cache_dir = '/var/cache/r10k'
$r10k_basedir = "${::settings::confdir}/environments"
$r10k_purgedirs = $r10k_basedir
$manage_configfile_symlink = false
$configfile_symlink = '/etc/r10k.yaml'

# Git configuration
$git_server = $::settings::ca_server
Expand Down
4 changes: 2 additions & 2 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
}

file { 'webhook_init_script':
content => template("${module_name}/etc/init.d/webhook.erb"),
content => template('r10k/webhook.erb'),
path => '/etc/init.d/webhook',
require => Package['sinatra'],
}
file { 'webhook_bin':
content => template("${module_name}/usr/local/bin/webhook.erb"),
content => template('r10k/webhook.erb'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any functional reason for this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not for this specific one, though using the name of the module instead of ${module_name} is preferable in terms of style.

Also, it is poor form to use fully qualified paths under templates or files as where the file ends up on the filesystem should be configurable anyhow so that design breaks down quickly.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's why line 77 from manifests/config.pp had to be changed, because the configfile is well, configurable :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting , I have not had anyone put their configuration file in a different location. Sounds logical to me though. I will say that fully qualified paths is a matter a preference, but in this case I totally see your point.

path => '/usr/local/bin/webhook',
notify => Service['webhook'],
}
Expand Down
153 changes: 152 additions & 1 deletion spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,156 @@
expect { subject }.to raise_error(Puppet::Error, /is not a bool/)
end
end
end

describe 'with manage_configfile_symlink' do
['true',true].each do |value|
context "set to #{value} with configfile specified and configfile_symlink left at the default value" do
let :params do
{
:manage_configfile_symlink => value,
:configfile => '/etc/puppet/r10k.yaml',
:cachedir => '/var/cache/r10k',
:manage_modulepath => false,
}
end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5',
:operatingsystem => 'Centos',
:is_pe => 'true',
}
end

it { should contain_file('symlink_r10k.yaml').with({
'ensure' => 'link',
'path' => '/etc/r10k.yaml',
'target' => '/etc/puppet/r10k.yaml',
})
}
end

context "set to #{value} with configfile specified and configfile_symlink specified" do
let :params do
{
:manage_configfile_symlink => value,
:configfile => '/etc/puppet/r10k.yaml',
:configfile_symlink => '/tmp/r10k.yaml',
:cachedir => '/var/cache/r10k',
:manage_modulepath => false,
}
end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5',
:operatingsystem => 'Centos',
:is_pe => 'true',
}
end

it { should contain_file('symlink_r10k.yaml').with({
'ensure' => 'link',
'path' => '/tmp/r10k.yaml',
'target' => '/etc/puppet/r10k.yaml',
})
}
end

context "set to #{value} without configfile_symlink specified" do
let :params do
{
:manage_configfile_symlink => value,
:configfile => '/etc/puppet/r10k.yaml',
:cachedir => '/var/cache/r10k',
:manage_modulepath => false,
}
end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5',
:operatingsystem => 'Centos',
:is_pe => 'true',
}
end
it { should contain_file('symlink_r10k.yaml').with({
'ensure' => 'link',
'path' => '/etc/r10k.yaml',
'target' => '/etc/puppet/r10k.yaml',
})
}
end
end

['false',false].each do |value|
context "set to #{value}" do
let :params do
{
:manage_configfile_symlink => value,
:configfile => '/etc/puppet/r10k.yaml',
:cachedir => '/var/cache/r10k',
:manage_modulepath => false,
}
end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5',
:operatingsystem => 'Centos',
:is_pe => 'true',
}
end

it { should_not contain_file('symlink_r10k.yaml') }
end
end

context 'set to a non-boolean value' do
let :params do
{
:manage_configfile_symlink => 'invalid',
:configfile => '/etc/r10k.yaml',
:cachedir => '/var/cache/r10k',
:manage_modulepath => false,
}
end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5',
:operatingsystem => 'Centos',
:is_pe => 'true',
}
end

it 'should fail' do
expect { subject }.to raise_error(Puppet::Error)
end
end
end

describe 'with configfile_symlink specified as a non fully qualified path' do
let :params do
{
:manage_configfile_symlink => true,
:configfile => '/etc/r10k.yaml',
:configfile_symlink => 'invalid/path',
:cachedir => '/var/cache/r10k',
:manage_modulepath => false,
}
end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5',
:operatingsystem => 'Centos',
:is_pe => 'true',
}
end

it 'should fail' do
expect { subject }.to raise_error(Puppet::Error)
end
end
end
Loading