forked from CERIT-SC/puppet-yum
-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#107) YUM update puppet task support
This adds a puppet task called yum that allows to run a yum update or upgrade through bolt. It also has a quiet parameter to run without output.
- Loading branch information
Showing
3 changed files
with
62 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
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,14 @@ | ||
{ | ||
"description": "Allows you to perform yum functions", | ||
"input_method": "stdin", | ||
"parameters": { | ||
"action": { | ||
"description": "Action to perform ", | ||
"type": "Enum[update, upgrade]" | ||
}, | ||
"quiet": { | ||
"description": "Run without output ", | ||
"type": "Optional[Boolean]" | ||
} | ||
} | ||
} |
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,28 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
|
||
require 'json' | ||
require 'open3' | ||
require 'puppet' | ||
|
||
def yum(action, quiet) | ||
cmd = ['yum', '-y'] | ||
cmd << '-q' unless quiet == false || quiet.nil? | ||
cmd << action | ||
|
||
stdout, stderr, status = Open3.capture3(*cmd) | ||
raise Puppet::Error, stderr unless status.success? | ||
{ status: stdout.strip } | ||
end | ||
|
||
params = JSON.parse(STDIN.read) | ||
action = params['action'] | ||
quiet = params['quiet'] | ||
|
||
begin | ||
result = yum(action, quiet) | ||
puts result.to_json | ||
exit 0 | ||
rescue Puppet::Error => e | ||
puts({ status: 'failure', error: e.message }.to_json) | ||
exit 1 | ||
end |