Open phinjensen opened 7 years ago
original author: Jon Jensen
date: 2012-03-23T00:35:44-04:00
Interesting and slick solution, Greg. Would Puppet's interface to Facter make it possible to write a generic function for finding the home directory of any user, not a hardcoded one?
Your Facter code that finds the home directory:
Facter::Util::Resolution.exec('/bin/grep "^postgres:" /etc/passwd | cut -d: -f6').chomp
... is crying out for a much simpler native Ruby solution without the subshell and two separate processes. This does the trick:
require 'etc' Etc.getpwnam('postgres').dir
And finally, I love that you used the Swedish Chef picture in your article about Puppet. :)
original author: Greg Sabino Mullane
date: 2012-03-23T11:24:02-04:00
Thanks for the Etc() tip, Jon. I originally wrote this as an exec() attempt and did not think to lookup a more direct Ruby solution. I am not sure about making a more generic interface for home directories. It would have to be something outside of facts, as they are always simply string key/value pairs. If there is some way I did not find it in my investigations.
original author: Greg Sabino Mullane
date: 2012-03-23T11:26:10-04:00
Yeah, glad you caught the Puppet/Chef reference. It was too good of a combo to pass up, and he is one of my favorite Muppets as well! I haven't used Chef enough to know how they would handle this situation; I know that you can put a lot more raw-Ruby into your manifests, but it might still run into the same chicken-and-egg problem.
original author: Thomas Eichberger
date: 2013-05-21T11:01:05-04:00
Even though this is an interesting idea, I would prefer a better design.
We now have a function which should return a fact, but this function suddenly has a side effect.
Side effects of functions are usually considered a bad thing, but of course there are exceptions.
original author: thm
date: 2014-09-26T03:32:04-04:00
thx! is working.
original author: Unknown
date: 2016-04-09T14:13:20-04:00
A simple rule is, you never need more than of grep, sed, awk, or cut in one pipe. For example, your grep-ing into cut may be Ok for a quick command-line, but if you are posting it for others, you ought to use a single sed or awk.
(If, of course, you do not implement it in Ruby entirely.)
Comments for https://www.endpointdev.com/blog/2012/03/puppet-custom-fact-ruby-plugin/ By Greg Sabino Mullane
To enter a comment: