Ok so I am playing with puppet/foreman. I know a lot of people frown on this but I like to sometimes have host name as node.location, this means my FQDN could be node.location.domain.net.au

This was a real pain because after my server was built and would talk to puppet, foreman would create a new node. So I set out to modify the facts that it utilises.

Please not these are dirty dirty modifications and only work with ccTLD type domains (anyone has some improvements please share).




if name = Facter::Util::Resolution.exec(‘hostname’) \

and name =~ /.*?\.\.(.+$)/

#     and name =~ /.*?\.(.+$)/



elsif domain = Facter::Util::Resolution.exec(‘dnsdomainname’) \

and domain =~ /([^.]*\.[^.]*\.[^.]*$)/

#      and domain =~ /.+\..+/

domain = $1





Facter.add(:hostname, :ldapname => “cn”) do

setcode do

#    hostname = nil

#    if name = Facter::Util::Resolution.exec(‘hostname’)

#      if name =~ /(.*?)\./

#        hostname = $1

#      else

#        hostname = name

#      end

#    end

#    hostname

hostname = Facter::Util::Resolution.exec(‘uname -n’)





I can’t take credit for the hosts one, i found this here : https://narvi.puppetlabs.com/attachments/1523/hostname.rb.patch

These files need to be modified on the nodes that happen to have a period in the hostname, and this post is so I don’t forget how I did it. 😛