-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(MODULES-11048) task to remove local filebucket
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 ```
- Loading branch information
gimmy
committed
Apr 15, 2021
1 parent
5b31400
commit 4a998b0
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"description": "Removes the local filebucket", | ||
"parameters": { | ||
"force": { | ||
"description": "ignore nonexistent files and errors", | ||
"type": "Optional[Boolean]" | ||
} | ||
}, | ||
"files": ["puppet_agent/files/rb_task_helper.rb"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'puppet' | ||
|
||
params = JSON.parse(STDIN.read) | ||
force = params['force'] | ||
require_relative File.join(params['_installdir'], 'puppet_agent', 'files', 'rb_task_helper.rb') | ||
|
||
module PuppetAgent | ||
class DeleteLocalFilebucket | ||
include PuppetAgent::RbTaskHelper | ||
|
||
def initialize(force) | ||
@force = force | ||
end | ||
|
||
def run | ||
begin | ||
FileUtils.remove_dir(clientbucketdir, force) | ||
{ "success": true } | ||
rescue StandardError => e | ||
return error_result( | ||
'puppet_agent/cannot-remove', | ||
"#{e.class}: #{e.message}" | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def clientbucketdir | ||
options = { | ||
failonfail: false, | ||
override_locale: false, | ||
} | ||
|
||
command = "#{puppet_bin} config print clientbucketdir" | ||
Puppet::Util::Execution.execute(command, options).strip | ||
end | ||
|
||
attr_reader :force | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
task = PuppetAgent::DeleteLocalFilebucket.new(force) | ||
puts task.run | ||
end |