New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
factsource crontab PATH conflicting with other cronjobs #207
Comments
I've always wanted native cron.d support in Puppet, now I have another technical reason for why I think cron.d is superior to |
here's an example demonstrating env var handling for multiple cronjobs. |
This is a serious limitation of But I would argue that the implementation here is flawed. It assumes that Currently not sure how to handle this more cleanly. |
the Dell srvadmin tools use this in
I use a modified script to set an in-house Ruby path, as I was experiencing obnoxious
you might be able to do some kind of trickery with a helper script or a custom fact? is there any reason to not set it explicitly? mcollectived sets it's own PATH environment very strictly. here's the results of
proposed fix would be:
|
Are you saying we should hardcode it? That would be an approach, and quite pragmatic at that. Here's my order of preference though:
The original code is by @reidmv apparently. Any thoughts? Pinging @richardc as well. |
I assume the intent is so this shebang line which is written in terms of I think it's a bad idea and should be just hardcoded to the $path fact |
The intent probably was to make sure the shebang found the right ruby, as @richardc suggests. If that's all it does, maybe the fix would be to remove the $ruby_shebang = $is_pe ? {
true => '/opt/puppet/bin/ruby',
default => '/usr/bin/env ruby',
}
# Template uses:
# - $yaml_fact_path_real
# - $ruby_shebang
file { "${mcollective::site_libdir}/refresh-mcollective-metadata":
owner => '0',
group => '0',
mode => '0755',
content => template('mcollective/refresh-mcollective-metadata.erb'),
before => Cron['refresh-mcollective-metadata'],
}
cron { 'refresh-mcollective-metadata':
command => "${mcollective::site_libdir}/refresh-mcollective-metadata >/dev/null 2>&1",
user => 'root',
minute => [ '0', '15', '30', '45' ],
} |
Crontab environment variables are global and we do not as a matter of best practice want to leak environment variables into other cron jobs. We still want to ensure the correct ruby is used to instantiate the refresh-mcollective-metadata script but we can accomplish this by templatizing the shebang line rather than relying on environment variables in the crontab. Closes voxpupuli#207
Crontab environment variables are global and we do not as a matter of best practice want to leak environment variables into other cron jobs. We still want to ensure the correct ruby is used to instantiate the refresh-mcollective-metadata script but we can accomplish this by templatizing the shebang line rather than relying on environment variables in the crontab. Closes voxpupuli#207
That doesn't feel right at all, for non-PE PATH may still need to be set as cron generally runs with a reduced environment. I think the correct thing here is leave the template alone, and just set PATH to $::path, with no attempt to extend it.
|
Agree, but do add a parameter for this. It is very likely that |
Even if Under puppet-agent |
Which gives me another idea: There are facts to identify PE, right? Should the module respect those and do the "right" thing to the best of its knowledge? |
I think the template munging is the correct way forward, since it doesn't pollute the environment of the cron. It is a limitation of standard unix cron for sure. |
Can we set the path for the cron job (which it sounds like is desirable) using something that doesn't leak into other jobs? e.g. cron { 'refresh-mcollective-metadata':
command => "PATH=${path} {mcollective::site_libdir}/refresh-mcollective-metadata >/dev/null 2>&1",
user => 'root',
path => $::path,
minute => [ '0', '15', '30', '45' ],
} It feels like we have two issues we're trying to solve for.
In the previous implementation the path was munged to try and increase the odds the right ruby version was used, and it was set globally. This was messy and inelegant and the side effects of that are I believe what prompted the issue to be opened. Although I'm open to alternatives, right now it seems to me like the best path forward (if it's technically valid) would be to add a path to the individual cron command as given above, and separately determine which shebang line to use to ensure the correct version of ruby is used to invoke the script. |
So I merged this, #217 maybe that was a mistake? Should we revert and get consensus? |
I added another proposed PR. #218 re-implements a PATH variable as part of the The PR leaves in place for now the shebang line templating, which causes the shebang to be Open for feedback. |
closing with the merge of #218 |
Crontab environment variables are global and we do not as a matter of best practice want to leak environment variables into other cron jobs. We still want to ensure the correct ruby is used to instantiate the refresh-mcollective-metadata script but we can accomplish this by templatizing the shebang line rather than relying on environment variables in the crontab. Closes voxpupuli#207
https://github.com/puppet-community/puppet-mcollective/blob/master/manifests/server/config/factsource/yaml.pp#L20
apparently, ENV variables set in
crontab
are global for all cronjobs. I actually run puppet via cron (https://github.com/theforeman/puppet-puppet/blob/master/manifests/agent/service.pp#L38)now every Puppet run bloats my PATH variable a little more until it looks like this:
X-Cron-Env: <PATH=/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin:/opt/puppet/bin...
The text was updated successfully, but these errors were encountered: