On Tuesday, September 2, 2014 6:42:11 AM UTC-7, jcbollinger wrote: > > > > 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 > > Hello Felix and John,
First, thank you both for your responses and information. In regards to John's post, you make a very interesting point and I didn't realize that I could achieve my objective without using a custom fact. My goal is to extract all site-specific data to Heira in the near future so this custom-fact exercise does seem worth while but thank you for pointing out these alternate ways to achieve my goal. Thanks again to both of you for the informative posts. Cheers, Mike -- 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/57d9f032-3adc-4291-be24-f0baa11e9a8b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.