Showing with 6 additions and 7 deletions.
  1. +1 −1 templates/r10k.yaml.erb
  2. +5 −6 templates/webhook.erb
2 changes: 1 addition & 1 deletion templates/r10k.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% @source_keys.sort.each do |source| -%>
<%=source-%>:
<% @r10k_sources[source].sort.each do |key,value| -%>
<%=key-%>: "<%=value%>"
<%=key-%>: <%=value%>
<% end -%>
<% end -%>
<% end %>
Expand Down
11 changes: 5 additions & 6 deletions templates/webhook.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ include MCollective::RPC


LOGFILE = '/var/lib/peadmin/webhook.log'
DEPLOYCMD = "/opt/puppet/bin/mco r10k deploy_all --np >> %{LOGFILE} 2>&1"
USER = 'puppet'
PASS = 'puppet'
PORT = '8088'
Expand All @@ -30,8 +29,8 @@ CLIENT_CFG = '/var/lib/peadmin/.mcollective'
CERT_NAME = 'peadmin'
DISCOVER_TIMEOUT = 10
CLIENT_TIMEOUT = 120
USE_MCO = true

USE_RUBY = false
PROTECTED = true

ENV['HOME'] = '/var/lib/peadmin'
ENV['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin:/opt/puppet/bin'
Expand All @@ -56,7 +55,7 @@ class Server < Sinatra::Base

# curl -d '{ "ref": "refs/heads/production" }' -H "Accept: application/json" 'https://puppet:puppet@localhost:8088/payload' -k -q
post '/payload' do
protected!
protected! if PROTECTED
request.body.rewind # in case someone already read it
data = JSON.parse(request.body.read, :quirks_mode => true)
branch = data['ref'].split("/").last
Expand All @@ -70,7 +69,7 @@ class Server < Sinatra::Base
helpers do
def deploy(branch)
begin
if USE_MCO
if USE_RUBY
result = mco(branch).first
if result.results[:statuscode] == 0
message = result.results[:statusmsg]
Expand All @@ -79,7 +78,7 @@ class Server < Sinatra::Base
end
else
message = 'forked'
Process.detach(fork{ exec "#{DEPLOYCMD} &"})
Process.detach(fork{ exec "/opt/puppet/bin/mco r10k deploy #{branch} >> #{LOGFILE} 2>&1 &"})
end
{:status => :success, :message => message.to_s }.to_json
rescue => e
Expand Down