>
> Found my own answer - so though i'd post it here incase anyone else is 
> trying to learn this stuff :)
>

The variable i was trying to reference was located inside a class, so it 
would have had to have been referenced as %{classname::variable}, this is 
considered bad practice as its not a top scope variable and it could run 
into issues further down the track - my solution was to create a puppet 
custom fact and reference it via ${::fact_name}

This is a snippet from my custom fact, so I hope it helps someone else;

All the hosts are named type-role-env-loc eg
int-vmhost-testing-location

machine_role.rb is the file name and i had it located in the base module 
puppet/modules/base/lib/facter <-- stuff in this dir 
(modulename/lib/facter) is automatically picked up by puppet.

Facter.add('machine_role') do
>   setcode do
>     $hostname = Facter.value('hostname')
>     case $hostname
>       when /-vmhost-/
>         $machine_role = 'vmhost'
>      when /-Othermachinenames-/
>         $machine_role = 'whatever'
>      default
>         $machine_role = 'unknown'
>      end
>   end
> end


so that above creates a puppet custom fact, which facter -p (-p tell it to 
use puppet custom manifests) will return 
machine_role => <rolename>

If you're testing on a local machine outside of puppet set your path to 
where the facter file is located

$ export FACTERLIB=~/puppet/modules/base/lib/facter:$FACTERLIB
$ facter machine_role
vmhost

inside hiera.conf i setup a hierarchy and one of the lines was...
 - role/%{::machine_role}

so I had a directory created inside the :datadir: dir called roles which 
contains files like
vmhost.yaml
whatever.yaml
unknown.yaml

also a quick way to see if things are working properly..

hiera -d -c /path/to/hiera.yaml param_to_check ::machine_role=vmhost

Once you have this setup in puppet and *IF* you have updated your 
hiera.conf make sure you restart puppet!

This gave me the ability if required to have different conditions for 
different host types as defined by their hostname.

Cheers
David

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/90ea51eb-aa01-42f3-b357-9aa77245cc80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to