Showing with 261 additions and 85 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 CHANGELOG
  3. +1 −1 Modulefile
  4. +19 −2 README.md
  5. +65 −0 files/stash_mco.rb
  6. +7 −3 files/webhook
  7. +9 −5 manifests/init.pp
  8. +7 −3 manifests/install.pp
  9. +25 −8 manifests/install/gem.pp
  10. +1 −1 manifests/mcollective.pp
  11. +6 −5 manifests/params.pp
  12. +6 −1 spec/classes/init_spec.rb
  13. +60 −3 spec/classes/install/gem_spec.rb
  14. +42 −35 spec/classes/install_spec.rb
  15. +9 −18 spec/classes/mcollective_spec.rb
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ spec/fixtures/manifests/site.pp
.DS_Store
*.swp
.bundle
.ruby-version
Gemfile.lock
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2.3.0 - Zack Smith
* Fold in #78, #75 and #73
2.2.7 - Zack Smith
* Bugfix for mcollective during puppet apply and webhook as non mco
2.2.7 - Zack Smith
Expand Down
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'zack-r10k'
version '2.2.8'
version '2.3.0'
source 'https://github.com/acidprime/r10k'
author 'zack'
license 'Apache License, Version 2.0'
Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/acidprime/r10k.png?branch=master)](https://travis-ci.org/acidprime/r10k)

This is the r10k setup module. It has a base class to configure r10k to
This is the r10k setup module. It has a base class to configure r10k to
synchronize dynamic environments. You can be simply used by declaring it:

```puppet
Expand All @@ -23,6 +23,23 @@ 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.

This module requires the [puppetlabs-ruby](https://github.com/puppetlabs/puppetlabs-ruby.git) module. In the event that your environment already includes
the module with some customization, you can use the `manage_ruby_dependency`
parameter to adjust how this module expresses that requirement.
The supported values are `include`,`declare`, or `ignore`. The values' behavior
is outlined below:

* *declare* **default** This will explicitly declare the ruby module.
Additional declarations of the ruby module will result in an inability to
compile a catalog.

* *include* This will simply include the ruby module. When combined with class
ordering, this will permit the user to manage the instantiation of the ruby module elsewhere, potentially with non-standard parameter values.

* *ignore* This will assume that ruby is handled via some other mechanism than
a puppet module named `ruby`. It is left to the user to insure the
requirement be met.

## 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`

Expand All @@ -36,7 +53,7 @@ r10k::configfile_symlink: /etc/r10k.yaml

![alt tag](https://gist.github.com/acidprime/7013041/raw/6748f6173b406c03067884199174ce1df313ad58/post_recieve_overview.png)

An mcollective agent is included in this module which can be used to do
An mcollective agent is included in this module which can be used to do
on demand synchronization. This mcollective application and agent can be
installed on all masters using the following class

Expand Down
65 changes: 65 additions & 0 deletions files/stash_mco.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/opt/puppet/bin/ruby
#
# This script is meant to be used with the external hooks script for Stash:
# https://marketplace.atlassian.com/plugins/com.ngs.stash.externalhooks.external-hooks
#
# The above plugin is used instead of the "Atlassian Post-Receive
# Webhooks plugin" because the Atlassian plugin does not support ignoring
# ssl self signed certificates.
#
# The external hook is useful beyond just this script, thus I prefer it.
#
require 'getoptlong'

opts = GetoptLong.new(
[ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
[ '--insecure', '-k', GetoptLong::NO_ARGUMENT ],
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
)

target = nil
insecure = nil

opts.each do |opt,arg|
case opt
when '--help'
puts <<-EOF
stash_mco.rb [OPTIONS]
-h, --help
show help
-t, --target [url]
the target url to post to
example: https://puppet:puppet@localhost:8088/payload
user/pass should be specified as part of the target
-k, --insecure
pass the 'insecure' flag to curl to ignore ssl cert verification
EOF

when '--target'
target = arg
when '--insecure'
insecure = '-k'
end
end

# the external-hooks script passes the following on stdin
#
# old_hash new_hash ref/ref/ref
#
# for example:
# 0000000000000000000000000000000000000000 ad91e3697d0711985e06d5bbbf6a7c5dc3b657f7 refs/heads/production
#
# All we care about is refs/heads/<branch_name>
#
# Test this script with:
# echo "000000 123456 refs/heads/production" | stash_mco.rb -k -t https://puppet:puppet@localhost:8088/payload

while post = gets
post_data = "{ \"ref\": \"#{post.split[2]}\" }"
end

system( "curl -q #{insecure} -d '#{post_data}' -H 'Accept: application/json' #{target}")

10 changes: 7 additions & 3 deletions files/webhook
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class Server < Sinatra::Base
# Simulate a github post:
# curl -d '{ "ref": "refs/heads/production" }' -H "Accept: application/json" 'https://puppet:puppet@localhost:8088/payload' -k -q
#
# Simulate a stash post:
# curl -d '{ "refChanges":[ { "refId":"refs/heads/production" } ] }' -H "Accept: application/json" 'https://puppet:puppet@localhost:8088/payload' -k -q
# If using stash look at the stash_mco.rb script included here.
# It will filter the stash post and make it look like a github post.
#
# Simulate a Gitorious post:
# curl -X POST -d '%7b%22ref%22%3a%22master%22%7d' 'http://puppet:puppet@localhost:8088/payload' -q
Expand All @@ -86,7 +86,11 @@ class Server < Sinatra::Base
# If prefix is enabled in our config file run the command to determine the prefix
if $config['prefix']
prefix = run_prefix_command(data.to_json)
deploy("#{prefix}_#{branch}")
if prefix.empty?
deploy(branch)
else
deploy("#{prefix}_#{branch}")
end
else
deploy(branch)
end
Expand Down
14 changes: 9 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$version = $r10k::params::version,
$modulepath = $r10k::params::modulepath,
$manage_modulepath = $r10k::params::manage_modulepath,
$manage_ruby_dependency = $r10k::params::manage_ruby_dependency,
$r10k_basedir = $r10k::params::r10k_basedir,
$package_name = $r10k::params::package_name,
$provider = $r10k::params::provider,
Expand All @@ -19,6 +20,8 @@
$include_prerun_command = false,
) inherits r10k::params {

$ruby_dependency_options=['include','declare','ignore']
validate_re($manage_ruby_dependency,$ruby_dependency_options)
if type($include_prerun_command) == 'string' {
$include_prerun_command_real = str2bool($include_prerun_command)
} else {
Expand All @@ -31,11 +34,12 @@
}

class { 'r10k::install':
package_name => $package_name,
version => $version,
provider => $provider,
keywords => $gentoo_keywords,
install_options => $install_options,
install_options => $install_options,
keywords => $gentoo_keywords,
manage_ruby_dependency => $manage_ruby_dependency,
package_name => $package_name,
provider => $provider,
version => $version,
}

class { 'r10k::config':
Expand Down
10 changes: 7 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$provider,
$keywords,
$install_options,
$manage_ruby_dependency,
) {

# There are currently bugs in r10k 1.x which make using 0.x desireable in
Expand All @@ -20,8 +21,8 @@
if $package_name == '' {
case $provider {
'portage': { $real_package_name = 'app-admin/r10k' }
'yum': { $real_package_name = 'rubygem-r10k' }
default: { $real_package_name = 'r10k' }
'yum': { $real_package_name = 'rubygem-r10k' }
default: { $real_package_name = 'r10k' }
}
} else {
$real_package_name = $package_name
Expand All @@ -40,7 +41,10 @@
}
'pe_gem', 'gem', 'yum', 'zypper': {
if $provider == 'gem' {
class { 'r10k::install::gem': version => $version; }
class { 'r10k::install::gem':
manage_ruby_dependency => $manage_ruby_dependency,
version => $version;
}
}
elsif $provider == 'pe_gem' {
include r10k::install::pe_gem
Expand Down
33 changes: 25 additions & 8 deletions manifests/install/gem.pp
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
# Install the r10k gem using system ruby
class r10k::install::gem (
$manage_ruby_dependency,
$version,
) {

#include ::r10k
require git

class { '::ruby':
rubygems_update => false,
anchor{'r10k::ruby_done':}
case $manage_ruby_dependency {
include: {
include ::ruby
include ::ruby::dev
Class['::ruby'] ->
Class['ruby::dev'] ->
Anchor['r10k::ruby_done']
}
declare: {
class { '::ruby':
rubygems_update => false,
}
include ::ruby::dev
Class['::ruby'] ->
Class['::ruby::dev'] ->
Anchor['r10k::ruby_done']
}
default: {
#This catches the 'ignore' case, and satisfies the 'default' requirement
#do nothing
}
}

include ruby::dev

# Explicit dependency chaining to make sure the system is ready to compile
# native extentions for dependent rubygems by the time r10k installation
# begins
Expand All @@ -20,8 +38,7 @@
include make
include gcc

Class['::ruby'] ->
Class['ruby::dev'] ->
Anchor['r10k::ruby_done'] ->
Class['gcc'] ->
Class['make'] ->
Package['r10k']
Expand Down
2 changes: 1 addition & 1 deletion manifests/mcollective.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
}

Service <| title == $mc_service |> {
subscribe +> [ File["${app_path}/${app_name}"], File["${app_path}/${agent_ddl}"] ],
subscribe +> [ File["${app_path}/${app_name}"], File["${agent_path}/${agent_ddl}"] ],
}
}
11 changes: 6 additions & 5 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Reasonable defaults for all classes
class r10k::params
{
$package_name = ''
$version = '1.3.1'
$manage_modulepath = false
$install_options = ''
$sources = undef
$package_name = ''
$version = '1.3.2'
$manage_modulepath = false
$manage_ruby_dependency = 'declare'
$install_options = ''
$sources = undef

# r10k configuration
$r10k_config_file = '/etc/r10k.yaml'
Expand Down
7 changes: 6 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
:is_pe => 'true'
}
end

it { should compile.with_all_deps }
it { should_not contain_class('r10k::prerun_command') }
end
context 'when manage_ruby_dependency has an invalid value' do
let (:params) {{'manage_ruby_dependency' => 'BOGON'}}
it 'should fail' do
expect { subject }.to raise_error(Puppet::Error, /"BOGON" does not match/)
end
end

['true',true].each do |value|
context "with param include_prerun_command set to #{value}" do
Expand Down
Loading