I am trying to supplement and ultimately provide a patch for ‘foreman’
which is an adjunct to puppet.
Essentially, there is a Hosts class which belongs_to Hostgroup and
Hostgroup class has a column called ‘ancestry’ which is actually a
Hostgroup (probably what is referred to as STI but I am not sure) and
thus within Foreman, nesting Hostgroups is not uncommon.
Thus I could have a Host that is called “ServerA”, that belongs to
“WebServer” Hostgroup which has an ancestry (Hostgroup) called “Base”
and for me to find out all of the puppetclasses that host “ServerA”
belongs to, I would have to get a listing of all of the puppetclasses
within the chain of Hostgroups to which ServerA belongs.
So this is my code…
@hosts.each do |host|
@ancestors = Hostgroup.find(host.hostgroup.ancestry) unless
host.hostgroup.ancestry == nil
@ancestors.puppetclasses.each do |anc|
@my_classes[anc.name] += 1
And this works for me because I am only nesting 1 level but it’s
conceivable that other users would nest many more levels and if my patch
is to be accepted, I undoubtedly have to account for an infinite level
How would I accomplish that?
Craig W. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Need help communicating between generations at work to achieve your
desired success? Let us help!