Skip to content

Commit

Permalink
fix webhook generate type functionailty for non-root user
Browse files Browse the repository at this point in the history
if webhook is running under unprivileged account it creates
.resource_types in it's home directory, instead of code directory
explicitly pass parameters to point to configured code location

modified ordering of service components to restart service
when service scripts have been updated
  • Loading branch information
vchepkov committed Mar 29, 2020
1 parent 4152610 commit 15570a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,30 @@
ensure => $ensure_file,
owner => $user,
group => $group,
before => File['webhook_bin'],
before => Service['webhook'],
}

file { '/var/log/webhook':
ensure => $ensure_directory,
owner => $user,
group => $group,
force => $ensure,
before => File['webhook_bin'],
before => Service['webhook'],
}

file { '/var/run/webhook':
ensure => $ensure_directory,
owner => $user,
group => $group,
before => File['webhook_init_script'],
before => Service['webhook'],
}

file { 'webhook_init_script':
ensure => $ensure_file,
content => template("r10k/${service_template}"),
path => $service_file,
mode => $service_file_mode,
before => File['webhook_bin'],
notify => Service['webhook'],
}

file { 'webhook_bin':
Expand Down
11 changes: 10 additions & 1 deletion templates/webhook.bin.erb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,16 @@ class Server < Sinatra::Base

def generate_types(environment)
begin
command = "#{$command_prefix} /opt/puppetlabs/bin/puppet generate types --environment #{environment.gsub(/\W/, '_')}"
<% if @user != 'root' -%>
<%# explicitly set working directories for non-root accounts -%>
<% @generate_suffix=' --confdir ' + scope.lookupvar('settings::confdir') +
' --codedir ' + scope.lookupvar('settings::codedir') +
' --vardir ' + scope.lookupvar('settings::vardir')
-%>
<% else -%>
<% @generate_suffix='' -%>
<% end -%>
command = "#{$command_prefix} /opt/puppetlabs/bin/puppet generate types --environment #{environment.gsub(/\W/, '_')}<%= @generate_suffix %>"

message = run_command(command)
$logger.info("message: #{message} environment: #{environment}")
Expand Down

0 comments on commit 15570a6

Please sign in to comment.