You cannot pass a variable to facter, because that's not how its model is designed. Facter is a tool that runs to gather relatively static system information, called facts. A fact with a given name has a given value. In other words, you need one unique fact for every value you're gathering. (though it can be nested into a data structure if needed.)
This is generally considered an anti-pattern in most cases. If you're reactive then your configuration rules aren't prescriptive. In other words, you cannot look at your code and predict what it will do. This means that your configuration isn't repeatable and you get yourself back into the bad old days where nobody really knew *for sure* what was on any given machine, or if it would even boot up again if you brought it down. Instead, you should prescribe the version of the package in question. In other words, move away from "if $package is version 1, then use config A, and if it's version 2 use config B" to "this node should be package version 2 with config B." To be sure, this pattern doesn't always work and you don't always have control over the full system. What's your use case that you're trying to solve? On Tue, May 14, 2019 at 2:19 AM Helmut Schneider <jumpe...@gmx.de> wrote: > Hi, > > before I reinvent the wheel: > > Does anyone know a custom fact that returns the version of an installed > package (if it is installed)? > > I assume it would be something like > > Facter.add(:package_version) do > setcode do > osfamily = Facter.value(:osfamily) > case osfamily > when /ubuntu|debian/ > Facter::Util::Resolution.exec("dpkg -l '*$my_package*' | grep > ^ii") > when 'freebsd' > Facter::Util::Resolution.exec("pkg info -ix $my_package*") > end > end > end > > but I have not found out yet how to pass a variable to facter. > > helmut@ubuntu:~$ puppet -V > 6.4.2 > helmut@ubuntu:~$ facter -v > 3.13.2 > helmut@ubuntu:~$ > > Thank you! > > -- > 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/xn0ltx8j23azj63000%40news.gmane.org > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CACkW_L6hoBP57eqVh4wxUNTbZY8xkJQ08shm1S3aN7QjcwyR3A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.