Created
August 28, 2013 18:29
-
-
Save reidmv/6369506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
metadata :name => "Yum", | |
:description => "Agent to manage packages using yum", | |
:author => "Reid Vandewiele", | |
:license => "Apache 2.0", | |
:version => "1.0", | |
:timeout => 60 | |
action "checkupdate", :description => "Checks for available yum updates" do | |
display :always | |
output :status, | |
:description => "The status of available updates", | |
:display_as => "Updates Available", | |
:default => "unknown" | |
end | |
action "install", :description => "install a package with yum" do | |
display :always | |
input :package, | |
:prompt => "Package Name", | |
:description => "The package to install", | |
:type => :string, | |
:validation => '^[a-zA-Z\-_\d]+$', | |
:optional => false, | |
:maxlength => 30 | |
output :status, | |
:description => "The status of the package install", | |
:display_as => "Install Status", | |
:default => "unknown status" | |
end |
This file contains hidden or 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
module MCollective | |
module Agent | |
class Yum<RPC::Agent | |
activate_when do | |
Facts['osfamily'] == "RedHat" | |
end | |
action "checkupdate" do | |
reply[:exitcode] = run("yum check-update", | |
:stdout => :output, | |
:stderr => :output, | |
:chomp => true | |
) | |
case reply[:exitcode] | |
when 0 | |
reply[:status] = "No Updates Available" | |
when 100 | |
reply[:status] = "Updates Available" | |
else | |
reply.fail! "UNKNOWN" | |
end | |
end | |
action "install" do | |
reply[:exitcode] = run("yum install #{request[:package]}", | |
:stdout => :output, | |
:stderr => :output, | |
:chomp => true | |
) | |
case reply[:exitcode] | |
when 0 | |
# noop, status is ok by default etc | |
when 1 | |
reply.fail! "ERROR" | |
else | |
reply.fail! "UNKNOWN" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment