EndPointCorp / end-point-blog

End Point Dev blog
https://www.endpointdev.com/blog/
17 stars 65 forks source link

Comments for Puppet custom facts and Ruby plugins to set a homedir #574

Open phinjensen opened 7 years ago

phinjensen commented 7 years ago

Comments for https://www.endpointdev.com/blog/2012/03/puppet-custom-fact-ruby-plugin/ By Greg Sabino Mullane

To enter a comment:

  1. Log in to GitHub
  2. Leave a comment on this issue.
phinjensen commented 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. :)

phinjensen commented 7 years ago
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.

phinjensen commented 7 years ago
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.

phinjensen commented 7 years ago
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.

phinjensen commented 7 years ago
original author: thm
date: 2014-09-26T03:32:04-04:00

thx! is working.

phinjensen commented 7 years ago
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.)