Skip to content

Commit

Permalink
(#107) YUM update puppet task support
Browse files Browse the repository at this point in the history
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
catay committed Jul 24, 2018
1 parent 248d260 commit 4929a78
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,26 @@ yum::install { 'package-name':

Please note that resource name must be same as installed package name.

### Puppet tasks

The module has a puppet task that allows to run `yum update` or `yum upgrade`.
Please refer to the [Bolt documentation](https://puppet.com/docs/bolt/latest/bolt.html) on how to execute a task.

```bash
$ bolt task show yum

yum - Allows you to perform yum functions

USAGE:
bolt task run --nodes <node-name> yum action=<value> [quiet=<value>]

PARAMETERS:
- action: Enum['update', 'upgrade']
Action to perform
- quiet: Optional[Boolean]
Run without output
```

---

This module was donated by CERIT Scientific Cloud, <support@cerit-sc.cz> to Vox Pupuli
14 changes: 14 additions & 0 deletions tasks/init.json
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]"
}
}
}
28 changes: 28 additions & 0 deletions tasks/init.rb
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

0 comments on commit 4929a78

Please sign in to comment.