-
Notifications
You must be signed in to change notification settings - Fork 193
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
(MODULES-11048) task to remove local filebucket #550
Conversation
override_locale: false, | ||
} | ||
|
||
command = "#{puppet_bin} config print clientbucketdir" |
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.
@joshcooper thoughts on this? Could this not return the correct path if clientbucketdir
is set in a different section?
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.
clientbucketdir
can also be found without shelling out to puppet config print.
Puppet.initialize_settings
Puppet[:clientbucketdir]
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.
Looks like clientbucketdir
is defined under the agent
section in defaults.rb. However, the puppet filebucket application doesn't enforce a specific run_mode, so it will ignore the value of clientbucketdir
if set under [agent]
.
Using this logic, I think we can rely on the initialize_settings
approach as it would be a bit faster.
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.
One downside with initialize_settings
is it can only be called once:
irb(main):001:0> require 'puppet'
=> true
irb(main):002:0> Puppet.initialize_settings
=> {}
irb(main):003:0> Puppet.initialize_settings
Traceback (most recent call last):
16: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
15: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/cli.rb:30:in `dispatch'
14: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
13: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
12: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
11: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/cli.rb:494:in `exec'
10: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:28:in `run'
9: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:63:in `kernel_load'
8: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:63:in `load'
7: from /home/josh/.rbenv/versions/2.7.3/bin/irb:23:in `<top (required)>'
6: from /home/josh/.rbenv/versions/2.7.3/bin/irb:23:in `load'
5: from /home/josh/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
4: from (irb):3
3: from /home/josh/work/puppet/lib/puppet.rb:153:in `initialize_settings'
2: from /home/josh/work/puppet/lib/puppet.rb:178:in `do_initialize_settings_for_run_mode'
1: from /home/josh/work/puppet/lib/puppet/settings.rb:305:in `initialize_global_settings'
Puppet::DevError (Attempting to initialize global default settings more than once!)
So it seems like there could be issues if this task was called twice in a plan (seems unlikely) or some other task also called initialize_settings
?
I'd be inclined to just shell out.
8292f29
to
191ae7f
Compare
tasks/delete_local_filebucket.rb
Outdated
) unless puppet_bin_present? | ||
|
||
begin | ||
FileUtils.remove_dir(clientbucketdir, force) |
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.
It may not worth fixing it, but if the clientbucketdir
is removed, the puppet command listing local filebuckets may error:
scrawny-tumbler:~ # find /opt/puppetlabs/puppet/cache/clientbucket/
find: `/opt/puppetlabs/puppet/cache/clientbucket/': No such file or directory
scrawny-tumbler:~ # puppet filebucket -l list
Error: Could not run: File not found
scrawny-tumbler:~ # mkdir /opt/puppetlabs/puppet/cache/clientbucket/
scrawny-tumbler:~ # puppet filebucket -l list
scrawny-tumbler:~ # puppet filebucket backup /etc/passwd --local
scrawny-tumbler:~ #
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 that puppet will create the directory again on the next run:
Debug: /File[/opt/puppetlabs/puppet/cache/clientbucket]: Adding autorequire relationship with File[/opt/puppetlabs/puppet/cache]
...
Debug: /File[/opt/puppetlabs/puppet/cache/clientbucket]/ensure: created
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.
Maybe we should just remove the directory contents then?
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.
good to merge, one optional comment
This adds a task that removes the local filebucket which was disabled by default in Puppet 7. The location of filebucket is determine using the `clientbucketdir` puppet config. ``` ❯ bolt task show puppet_agent::delete_local_filebucket puppet_agent::delete_local_filebucket Removes the local filebucket Usage bolt task run puppet_agent::delete_local_filebucket --targets <targets> [force=<value>] Parameters force Optional[Boolean] ignore nonexistent files and errors ```
This adds a task that removes the local filebucket
which was disabled by default in Puppet 7.
The location of filebucket is determined using the
clientbucketdir
puppet config.Tested on Windows: