On Friday, August 29, 2014 5:05:01 PM UTC-5, Mike Reed wrote: > > Hello all, > > To start, I would like to thank you in advance for your responses. > > I'm attempting to create a custom fact that will determine the network > location of a node, based on it's hostname. Ideally this would be run on a > node prior to the rest of the puppet modules because I will use the result > as a top scope variable to assign certain values to nodes, based on their > network location. My node hostnames currently subscribe to this convention: > > network-hostname/role-number (ie. home-elastic-01/work-mysql-02) >
I would like to suggest that you *not* do this via a fact. More generally, I consider it a principle of a good design to avoid creating any fact that is strictly derivative of other facts. You can get a top scope variable with the same value in several other ways, principal among them: 1. Compute it directly at top scope in your site manifest 2. Compute it in a class that manages no resources, 'include' that class at top scope, and set the top-scope variable from the class variable As a subset of (1), you could consider creating and using a custom function, which would be very clean as far as your manifests go. Note, however, that for *most* purposes you don't actually need a top-scope variable; you could instead use a class variable directly. Either way, you should be using a fully-qualified name everywhere you refer to the variable in your manifests, so the choice of namespace is mostly a personal preference in that context. The only use I can think of where you actually need a top-scope variable is if you want to interpolate it into Hiera hierarchy definitions (which is indeed a perfectly reasonable thing to do). Option 2 might look like this: modules/site/manifests/hostname_info.pp: ---- class site::hostname_info { $hostname_parts = split($::hostname, '-') $network = $hostname_parts[0] $role = $hostname_parts[1] $number = $hostname_parts[2] } manifests/site.pp (or any other manifest where you need the info): ---- # ... include 'site::hostname_info' $host_network = $site::hostname_info::network # ... John -- 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/8776edc6-7284-4410-b741-af1a8d6b7299%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.