Ask Your Question

custom facts with stdlib

asked 2016-06-01 11:58:06 -0500

erichymowitz gravatar image

updated 2016-06-02 06:32:31 -0500


Facter 1.6.18 / puppet 2.7..26

I would like to create some custom facts. I know that the ability was added in Facter 1.7 , but I keep reading references that the stdlib module allows custom facts. As far as I can tell, I'm using the stdlib module (I can't find the version number), but I can't figure out how to add custom facts with stdlib.

Update: @Tozz gave me the boost I needed to phrase my question better.

The stdlib module includes includes a file /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb which says

# A Facter plugin that loads facts from /etc/facter/facts.d
# and /etc/puppetlabs/facter/facts.d.
# Facts can be in the form of JSON, YAML or Text files
# and any executable that returns key=value pairs.

So I put a file /etc/facter/facts.d/test.txt including this one line


But when I run facter, I don't see my fact anywhere. This is what I am trying to do. Do I need to "activate" this feature somehow?


PS please don't ask me to upgrade. That is not an option.

edit retag flag offensive close merge delete


I think you need to do "facter -p" to see your custom facts.

bschonecker gravatar imagebschonecker ( 2016-06-02 10:22:20 -0500 )edit

@bschonecker Nope, didn't work.

erichymowitz gravatar imageerichymowitz ( 2016-06-02 12:05:54 -0500 )edit

if you do 'facter -p | grep plesk' does your custom fact even show up regardless of its value?

bschonecker gravatar imagebschonecker ( 2016-06-02 12:23:17 -0500 )edit

@bschonecker "facter -p | grep hymowitz" only shows one fact, "id => ehymowitz" because that is my login account. It does not show my custom fact "erichymowitz => 1". Same results when I try setting the value to 0, 2, or foobar.

erichymowitz gravatar imageerichymowitz ( 2016-06-02 13:07:33 -0500 )edit

does it work in puppet but not raw facter? try sudo puppet apply -e 'notice($erichymowitz)' Also try manually specifying your facterlib... "$ FACTERLIB=/etc/facter/facts.d/ facter"

DarylW gravatar imageDarylW ( 2016-06-02 16:45:12 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-06-02 15:55:04 -0500

xaz gravatar image

I just want to continue the thread since it's talking about custom fact and I need it in our environment. Basically, the custom fact I need to add is "environment" the variable setting in puppet managed node puppet.conf file. When a new puppet managed node is joining in our environment, the first thing the managed node needs to have in its puppet.conf file is "enviornment=development|staging|production". However, currently we don't have a good way to handle where the value comes from. Therefore, adding a new node requires some manual editing. Does custom fact help? How does it work to make that happen? Thanks. - xinhuan

edit flag offensive delete link more


I'm almost positive that puppet provides a $environment (or perhaps $::environment) variable separate from facter.

erichymowitz gravatar imageerichymowitz ( 2016-06-03 07:47:15 -0500 )edit

I'm not expert, but as far as I can tell, the agent must tell the master which environment it is in (puppet.conf) . The master (afaict) cannot "put" the client into an environment.

erichymowitz gravatar imageerichymowitz ( 2016-06-03 07:49:32 -0500 )edit

I used puppetlabs external custom facts as documented and it worked. I saved a shell script into <prefix>/<module>/facts.d/ and made it executable. The variable defined in can be accessed just like "::osfamily" variable. Note don't use 'environment' in script.

xaz gravatar imagexaz ( 2016-06-12 11:12:14 -0500 )edit

answered 2016-06-02 03:38:09 -0500

Tozz gravatar image

I'm not sure i understand correctly, but stdlib doesn't allow nor prohibit you from creating custom facts. Its just that you will most likely need features included in stdlib (like string comparisons, type casting, etc).

e.g. a very simple custom fact to verify the installed Plesk version could be done as following. File is in code/environments/production/modules/custom/lib/facter/plesk.rb:

# mysql command line to execute queries
mysqlcmd = 'mysql -u admin -p`cat /etc/psa/.psa.shadow` psa -N -e '

Facter.add(:pleskversion) do
  setcode do
    is_installed = false
    os = Facter.value('operatingsystem')
    case os
      when "RedHat", "CentOS", "SuSE", "Fedora"
        is_installed = system 'rpm -q psa > /dev/null 2>&1'
      when "Debian", "Ubuntu"
        is_installed = system 'dpkg -l psa > /dev/null 2>&1'
    if is_installed then
      %x[#{mysqlcmd} "SELECT val FROM misc WHERE param = 'version'"].strip

In your manifest you can do something like:

if $pleskversion == "x.x" {
  # do magic here
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-01 11:58:06 -0500

Seen: 1,060 times

Last updated: Jun 02 '16