Created
October 24, 2013 08:31
-
-
Save mbornoz/7133330 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
# crm_support: true/nil | |
# Whether there is Pacemaker installed | |
Facter.add('crm_support') do | |
confine :kernel => :linux | |
setcode do | |
crm_resource = Facter::Util::Resolution.exec('which crm_resource') | |
crm_resource.nil? ? nil : true | |
end | |
end | |
crm_resources = [] | |
Facter.add('crm_raw_resources') do | |
confine :crm_support => true | |
resources = Facter::Util::Resolution.exec('crm_resource -l') | |
if resources.nil? | |
setcode { 0 } | |
else | |
crm_resources = resources.split | |
setcode { crm_resources.join(',') } | |
end | |
end | |
crm_resources.each do |resource| | |
command = "crm_resource --resource #{resource} --locate" | |
crm_output = Facter::Util::Resolution.exec(command) | |
location = /^resource #{resource} is running on: (.+?)\s?\w*$/.match(crm_output)[1] | |
if resource =~ /^\w+:(0|1)$/ # Master/Slave resources | |
_resource = resource.split(':')[0] | |
if crm_output =~ /^.*\sMaster$/ | |
fact_name = "crm_#{_resource}_master" | |
else | |
fact_name = "crm_#{_resource}_slave" | |
end | |
else | |
fact_name = "crm_#{resource}" | |
end | |
Facter.add(fact_name) { setcode { location } } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment