Showing with 38 additions and 16 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 CHANGELOG
  3. +1 −1 Modulefile
  4. +22 −5 files/webhook
  5. +1 −2 manifests/mcollective.pp
  6. +3 −3 manifests/params.pp
  7. +1 −1 manifests/postrun_command.pp
  8. +1 −1 manifests/prerun_command.pp
  9. +4 −3 manifests/webhook.pp
  10. +2 −0 manifests/webhook/config.pp
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pkg
spec/fixtures/manifests/site.pp
.DS_Store
*.swp
.bundle
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2.2.7 - Zack Smith
* Bugfix for mcollective during puppet apply and webhook as non mco
2.2.7 - Zack Smith
* forge cut
2.2.6 - 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.7'
version '2.2.8'
source 'https://github.com/acidprime/r10k'
author 'zack'
license 'Apache License, Version 2.0'
Expand Down
27 changes: 22 additions & 5 deletions files/webhook
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Jeff Malnick

require 'rubygems'

require 'sinatra/base'
require 'webrick'
require 'webrick/https'
Expand All @@ -17,6 +16,7 @@ require 'mcollective'
require 'resolv'
require 'json'
require 'yaml'
require 'cgi'
include MCollective::RPC


Expand Down Expand Up @@ -60,15 +60,26 @@ 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
#
# Somulate a stash post:
# Simulate a stash post:
# curl -d '{ "refChanges":[ { "refId":"refs/heads/production" } ] }' -H "Accept: application/json" 'https://puppet:puppet@localhost:8088/payload' -k -q
#
# Simulate a Gitorious post:
# curl -X POST -d '%7b%22ref%22%3a%22master%22%7d' 'http://puppet:puppet@localhost:8088/payload' -q
# Yes, Gitorious does not support https...

post '/payload' do
protected! if $config['protected']
$logger.info("authenticated: #{$config['user']}")
request.body.rewind # in case someone already read it
data = JSON.parse(request.body.read, :quirks_mode => true)

# Check if content type is x-www-form-urlencoded
if request.content_type.to_s.downcase.eql?('application/x-www-form-urlencoded')
decoded = CGI::unescape(request.body.read).gsub(/^payload\=/,'')
else
decoded = request.body.read
end
data = JSON.parse(decoded, :quirks_mode => true)

# github sends a 'ref', stash sends an array in 'refChanges'
branch = ( data['ref'] || data['refChanges'][0]['refId'] ).split("/").last

Expand Down Expand Up @@ -96,8 +107,14 @@ class Server < Sinatra::Base
raise result.results[:statusmsg]
end
else
message = "triggered: /opt/puppet/bin/mco r10k deploy #{branch} >> #{$config['mco_logfile']} 2>&1 &"
Process.detach(fork{ exec "/opt/puppet/bin/mco r10k deploy #{branch} >> #{$config['mco_logfile']} 2>&1 &"})
if $config['use_mcollective']
command = "/opt/puppet/bin/mco r10k deploy #{branch} >> #{$config['mco_logfile']} 2>&1 &"
else
# If you don't use mcollective then this hook needs to be running as r10k's user i.e. root
command = "/opt/puppet/bin/r10k deploy environment #{branch} >> #{$config['mco_logfile']} 2>&1 &"
end
message = "triggered: #{command}"
Process.detach(fork{ exec "#{command}"})
end
$logger.info("message: #{message} branch: #{branch}")
{:status => :success, :message => message.to_s }.to_json
Expand Down
3 changes: 1 addition & 2 deletions manifests/mcollective.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
owner => 'root',
group => 'root',
mode => '0644',
notify => Service[$mc_service],
}
# Install the agent and its ddl file
file { "${app_path}/${app_name}" :
Expand All @@ -30,6 +29,6 @@
}

Service <| title == $mc_service |> {
subscribe +> File["${app_path}/${app_name}"],
subscribe +> [ File["${app_path}/${app_name}"], File["${app_path}/${agent_ddl}"] ],
}
}
6 changes: 3 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class r10k::params
{
$package_name = ''
$version = '1.1.0'
$version = '1.3.1'
$manage_modulepath = false
$install_options = ''
$sources = undef
Expand All @@ -21,7 +21,7 @@
$remote = "ssh://${git_server}${repo_path}/modules.git"

# prerun_command in puppet.conf
$prerun_command = 'r10k deploy environment -p'
$pre_postrun_command = 'r10k deploy environment -p'

# Gentoo specific values
$gentoo_keywords = ''
Expand All @@ -45,7 +45,7 @@
$webhook_prefix = false
$webhook_prefix_command = '/bin/echo example'
$webhook_enable_ssl = true

$webhook_use_mcollective = true

if $::is_pe =~ /true/ {
# Puppet Enterprise specific settings
Expand Down
2 changes: 1 addition & 1 deletion manifests/postrun_command.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This class will configure r10k to run as part of the masters agent run
class r10k::postrun_command (
$command = $r10k::params::postrun_command,
$command = $r10k::params::pre_postrun_command,
$ensure = 'present',
) inherits r10k::params {

Expand Down
2 changes: 1 addition & 1 deletion manifests/prerun_command.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This class will configure r10k to run as part of the masters agent run
class r10k::prerun_command (
$command = $r10k::params::prerun_command,
$command = $r10k::params::pre_postrun_command,
$ensure = 'present',
) inherits r10k::params {

Expand Down
7 changes: 4 additions & 3 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
require => Package['sinatra'],
before => File['webhook_bin'],
}

file { 'webhook_bin':
source => 'puppet:///modules/r10k/webhook',
path => '/usr/local/bin/webhook',
notify => Service['webhook'],
source => 'puppet:///modules/r10k/webhook',
path => '/usr/local/bin/webhook',
notify => Service['webhook'],
}

service { 'webhook':
Expand Down
2 changes: 2 additions & 0 deletions manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$prefix = $r10k::params::webhook_prefix,
$prefix_command = $r10k::params::webhook_prefix_command,
$enable_ssl = $r10k::params::webhook_enable_ssl,
$use_mcollective = $r10k::params::webhook_use_mcollective,
$configfile = '/etc/webhook.yaml',
) inherits r10k::params {

Expand All @@ -43,6 +44,7 @@
'prefix' => $prefix,
'prefix_command' => $prefix_command,
'enable_ssl' => $enable_ssl,
'use_mcollective' => $use_mcollective,
}
} else {
validate_hash($hash)
Expand Down