voxpupuli / puppet-r10k

Setup and configure r10k for use with git based environments in puppet
https://forge.puppet.com/puppet/r10k
Apache License 2.0
98 stars 169 forks source link

/usr/local/bin/webhook PATH variable should include /usr/local/bundle/bin #373

Closed luksi1 closed 6 years ago

luksi1 commented 7 years ago

I booted up a Docker image and ran the following code to get the r10k webhook running:

class { 'r10k':
  sources => {
    'puppet' => {
      'remote'  => 'https://git.domain.com/puppet-modules/puppet-controlrepo.git',
      'basedir' => "${::settings::environmentpath}",
      'prefix'  => false,
    },
  },
  manage_modulepath => false
}

class { 'r10k::webhook':
  use_mcollective => false,
  user            => 'root',
  group           => '0',
  require         => Class['r10k::webhook::config'],
}

class {'r10k::webhook::config':
  use_mcollective  => false,
  public_key_path  => '/etc/mcollective/server_public.pem',  # Mandatory for FOSS
  private_key_path => '/etc/mcollective/server_private.pem', # Mandatory for FOSS
}

And I get the following stacktrace:

[2017-05-30 07:06:40] ERROR message:
sh: 1: r10k: not found
 trace: ["/usr/local/bin/webhook:229:in `block in run_command'", "/usr/local/bin/webhook:215:in `open'", "/usr/local/bin/webhook:215:in `run_command'", "/usr/local/bin/webhook:332:in `deploy'", "/usr/local/bin/webhook:173:in `block in <class:Server>'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `call'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `block in compile!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `[]'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (3 levels) in route!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:994:in `route_eval'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (2 levels) in route!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1015:in `block in process_route'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `catch'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `process_route'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:973:in `block in route!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `each'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `route!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1085:in `block in dispatch!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1082:in `dispatch!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `block in call!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `call!'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:895:in `call'", "/usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'", "/usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'", "/usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'", "/usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'", "/usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'", "/usr/local/bundle/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'", "/usr/local/bundle/gems/rack-1.6.8/lib/rack/nulllogger.rb:9:in `call'", "/usr/local/bundle/gems/rack-1.6.8/lib/rack/head.rb:13:in `call'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/show_exceptions.rb:25:in `call'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in `call'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in `call'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `block in call'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1787:in `synchronize'", "/usr/local/bundle/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `call'", "/usr/local/bundle/gems/rack-1.6.8/lib/rack/handler/webrick.rb:88:in `service'", "/opt/puppetlabs/puppet/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'", "/opt/puppetlabs/puppet/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'", "/opt/puppetlabs/puppet/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'"]

The simple solution appears to be to change this line in the webhook:

ENV['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin:/opt/puppetlabs/puppet/bin:/usr/local/bin'

to this:

ENV['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin:/opt/puppetlabs/puppet/bin:/usr/local/bin:/usr/local/bundle/bin'
rnelson0 commented 7 years ago

I don't see the path /usr/local/bundle on any of my systems. Are you sure this isn't something particular to your container image?

luksi1 commented 6 years ago

My container is from the Ruby library on dockerhub, https://hub.docker.com/_/ruby/, which uses /usr/local/bundle/bin.

I'm using Ruby 2.3. If this isn't something that the project is considering supporting, feel free to close this issue.

ghoneycutt commented 6 years ago

@luksi1 it might help to run a supported version of ruby for your version of Puppet. Puppet v4 uses Ruby 2.1.9 and v5 uses 2.4.1.

rnelson0 commented 6 years ago

@luksi what distro is that image based on, or is ruby compiled from source? If it’s a common distro, we could update the params.

I think the paths used in the ERB template are based on common distributions’ file locations, and if you need to change that path, then we need to modify https://github.com/voxpupuli/puppet-r10k/blob/master/templates/webhook.bin.erb to support an optional path string. Until then, you could possibly work around it by creating a symlink yo one of those directories.

luksi1 commented 6 years ago

The official Ruby Docker images are compiled from source.

Thanks for the tip. I simply rebuilt the image with the correct path locations. It's only a bit of a pain, as it would be nicer to simply be able to pull the Docker image and run r10k right out for the box with the paths correct.

I totally understand the focus on common distro locations. That seems natural. The use case, in this scenario, was breaking out the r10k functionality as a Docker container and it seemed a bit heavy-handed to use an OS distro, as opposed to a slimmed down Ruby image.

I'm actually going to go ahead and close this, as it's abundantly clear as I write this that this is clear edge case, even if the change would be slight. Thanks for the feedback!