-
Notifications
You must be signed in to change notification settings - Fork 229
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
WIP/RFC: Add run_agent
task
#709
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,160 @@ | |||
#!/opt/puppetlabs/puppet/bin/ruby |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the most sensible default. Non AIO users can override this in their bolt configuration with interpreters
.
tasks/run_agent.rb
Outdated
require 'etc' | ||
require 'json' | ||
require 'yaml' | ||
require_relative '../../ruby_task_helper/files/task_helper.rb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add puppetlabs/ruby_task_helper
to the metadata.json?
As far as the module is concerned, it's a 'soft' dependency. But I also don't envisage a module namespace clash, so adding it to the metadata might be more helpful to users.
require 'yaml' | ||
require_relative '../../ruby_task_helper/files/task_helper.rb' | ||
|
||
class RunAgentTask < TaskHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what to use for the class name. The docs aren't especially helpful.
if agent_locked? | ||
raise TaskHelper::Error.new( | ||
'Lockfile still exists after waiting', | ||
'theforeman-puppet/lockfile_timeout_expired' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure if this is a good choice or how important it is.
) | ||
end | ||
|
||
waited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I'm actually using this returned value at the moment. I suppose I could bung it into the response??
tasks/run_agent.rb
Outdated
cmd << if @noop | ||
'--noop' | ||
else | ||
'--no-noop' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to override the value in the config file. I should probably make this clearer in whatever docs I write or in the task metadata.
case status.exitstatus | ||
when 0 | ||
{ | ||
result: 'The run succeeded with no changes or failures; the system was already in the desired state (or --noop was used).', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this text was taken from the puppet docs. I added the bit about noop
myself. Maybe I should open a PR to fix this upstream ;)
e8e7da3
to
10359ab
Compare
Quoting myself from https://gist.github.com/alexjfisher/753c61e09e891c9c9336ba0522b581a4#gistcomment-3057265
That is, if you use |
tasks/run_agent.rb
Outdated
end | ||
|
||
def run_puppet | ||
cmd = [@puppet_bin, 'agent', '-t', '--detailed-exitcodes'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, with #709 (comment) I was of course referring to this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a manual run (as opposed to a normal scheduled run), I think I'd personally never want to accidentally be using the cache. I do need a way of making this and other options configurable though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--detailed-exitcodes
is redundant here though (already included in -t
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agreed, having a simple toggle for --test
(which doesn't use cache) and --no-daemonize --onetime --no-splay --detailed-exitcodes
(which would use cache) would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you override options set with --test
by setting conflicting arguments?
eg does
puppet agent -t --usecacheonfailure
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
answering my own question... Apparently not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it:
$ puppet apply --noop -e 'file { "/tmp/omgtest": ensure => file, }'
Notice: Compiled catalog for managua.lan in environment production in 0.01 seconds
Notice: /Stage[main]/Main/File[/tmp/omgtest]/ensure: current_value 'absent', should be 'file' (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 event
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.02 seconds
$ puppet apply --noop -e 'file { "/tmp/omgtest": ensure => file, }' --no-noop
Notice: Compiled catalog for managua.lan in environment production in 0.01 seconds
Notice: /Stage[main]/Main/File[/tmp/omgtest]/ensure: created
Notice: Applied catalog in 0.01 seconds
And yes, it'd be much better to use the default --test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work just fine with puppet apply
. Last argument takes precedence:
$ puppet apply --no-noop -e 'file { "/tmp/omgtest": ensure => file, }' --noop
Notice: Compiled catalog for managua.lan in environment production in 0.01 seconds
Notice: /Stage[main]/Main/File[/tmp/omgtest]/ensure: current_value 'absent', should be 'file' (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 event
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.01 seconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for puppet agent -t --splay
and the run didn't wait a random amount of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@runejuhl I've added a puppet_settings
variable. It's an optional hash where you can override the default settings.
e6687f8
to
9182626
Compare
extra: | ||
- gem: bolt | ||
version: '~> 1.15' | ||
# TODO: Add something to foreman-installer-modulesync to support `unless ENV['PUPPET_VERSION'] =~ /^5/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekohl a raw_append
option??
9182626
to
5b2946a
Compare
@alexjfisher what do we want to do with this? I don't have bolt or the capability to maintain this. Would you be interested in becoming a co-maintainer for the module? |
No description provided.