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")
olddrbd=false
else
old
drbd=true
end

if olddrbd==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
resourcename=%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