Custom fact producing master data but not agent data for role.

asked 2017-11-06 08:01:30 -0600

markhorrocks gravatar image

updated 2017-11-07 09:25:28 -0600

I have installed puppetmaster and puppet-agent (5.3) in VM's on separate local machines.

puppet agent --test works fine on the agent with the following output.

root@ubuntu-dell-vm:/etc/puppetlabs/code/modules# puppet agent --test
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ubuntu-dell-vm
Info: Applying configuration version '1509974427'

I have written a custom fact in /etc/puppetlabs/code/environments/production/modules/custom/lib/facter/role.rb. The file is at /opt/puppetlabs/puppet/cache/lib/facter/role.rb on the agent

Running facter --puppet works on both the server and the agent but produces a role name for the master on both machines. Hostname is correct on the agent but role is incorrect. How do I get facter to give me the agent's role? Here is my role.rb.

Facter.add(:role) do
  role = ""

  hostname = Facter.value('hostname')

  case hostname

    when /^(\w+)\d+/
      role = "#{$1}_server"       # ie: www1 -> www_server
      role = "#{hostname}_server" # ie: www -> www_server

    setcode do
edit retag flag offensive close merge delete