Puppet Recipe: How to determine the role of a drbd device?

  |   Source

It's not perfect, but this little facter script helps to determine which role a drbd device has.

This is a puppet faceter plugin, you should put it somewhere under
/etc/puppet/modules/drbd/plugins/facter/drbd_role.rb

It checks which version of drbd you are running, the older DRBD setups had their config in /etc/drbd.conf, the newer versions especially on Ubuntu do have their resource config in /etc/drbd.d/.res


require 'facter'

filename=""
if File::exist?('/sbin/drbdadm')
if File::exist?("/etc/drbd.d")
old_drbd=false
else
old_drbd=true
end

if old_drbd==false
Dir.glob('/etc/drbd.d/.res') do | fileitem |
next if fileitem == '.' or fileitem == '..'
filename=File::basename(fileitem,'.res')
end
end

if old_drbd
role=%x{drbdadm role grep "resource" /etc/drbd.conf|awk '{print $2}'}.chomp.downcase
else
resource_name=%x{cat /etc/drbd.d/#{filename}.res|grep "resource"|awk '{print $2}'}.chomp.downcase
role=%x{drbdadm role #{resource_name}}.chomp.downcase
end

Facter.add("drbd_role") do
setcode do
role
end
end
end