FAQ
I've got a custom fact that spits out a list of server types (web, app, db,
etc). I'd like to do classification on this fact, but when I try using one
of the server types in my hiera config, it doesn't work.

For simplicity, I've tested with another fact (filesystems) that also
returns multiple values.


*# this is a typical facter output for filesystems*
root@puppetmaster:/etc/puppet/hieradata# facter filesystems
ext4,iso9660

*# my hiera.yaml, to show the first entry in my hierarchy is for the
filesystems fact*
root@puppetmaster:/etc/puppet/hieradata# cat /etc/hiera.yaml
---
:backends:
   - yaml

:hierarchy:
     - "%{filesystems}"
     - global
     - "nodes/%{clientcert}"
     - "groups/%{server_groups}"
     - "environment_%{environment}"
     - "os/%{osfamily}"
     - "os/%{osfamily}/%{operatingsystemmajrelease}"
     - "virtual_%{::virtual}"
     - defaults
     - credentials

:yaml:
   :datadir: /etc/puppet/hieradata


*# my yaml file has a an entry for motd::banner (my 'play with' data)*
root@puppetmaster:/etc/puppet/hieradata# cat
/etc/puppet/hieradata/ext4.yaml
---

motd::banner: this is for the ext4 filesystem


*# without any facts, I get the default*
root@puppetmaster:/etc/puppet/hieradata# hiera motd::banner
Hi there! This system is managed by puppet. (defaults.yaml)


*# with the filesystem fact set to ext4, I get the right value*
root@puppetmaster:/etc/puppet/hieradata# hiera motd::banner filesystems=ext4
this is for the ext4 filesystem

*# with the filesystem fact set to exactly what I get from facter, I'm back
to the default*
root@puppetmaster:/etc/puppet/hieradata# hiera motd::banner
filesystems=ext4,iso9660
Hi there! This system is managed by puppet. (defaults.yaml)


Is it possible to use a fact that contains multiple values within hiera? If
so, what am I missing? If not, what's the point of having facts with
multiple values in the first place?


Paul

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5db68d98-9924-499d-8cee-56d942c94df7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • William Leese at Dec 12, 2013 at 5:03 am

    On Thursday, December 12, 2013 7:33:26 AM UTC+9, Paul Archer wrote:
    *# this is a typical facter output for filesystems*
    root@puppetmaster:/etc/puppet/hieradata# facter filesystems
    ext4,iso9660

    *# my hiera.yaml, to show the first entry in my hierarchy is for the
    filesystems fact*
    root@puppetmaster:/etc/puppet/hieradata# cat /etc/hiera.yaml
    ---
    :backends:
    - yaml

    :hierarchy:
    - "%{filesystems}"
    - global
    - "nodes/%{clientcert}"
    - "groups/%{server_groups}"
    - "environment_%{environment}"
    - "os/%{osfamily}"
    - "os/%{osfamily}/%{operatingsystemmajrelease}"
    - "virtual_%{::virtual}"
    - defaults
    - credentials

    :yaml:
    :datadir: /etc/puppet/hieradata


    *# my yaml file has a an entry for motd::banner (my 'play with' data)*
    root@puppetmaster:/etc/puppet/hieradata# cat
    /etc/puppet/hieradata/ext4.yaml
    ---

    motd::banner: this is for the ext4 filesystem


    *# without any facts, I get the default*
    root@puppetmaster:/etc/puppet/hieradata# hiera motd::banner
    Hi there! This system is managed by puppet. (defaults.yaml)


    *# with the filesystem fact set to ext4, I get the right value*
    root@puppetmaster:/etc/puppet/hieradata# hiera motd::banner
    filesystems=ext4
    this is for the ext4 filesystem

    *# with the filesystem fact set to exactly what I get from facter, I'm
    back to the default*
    root@puppetmaster:/etc/puppet/hieradata# hiera motd::banner
    filesystems=ext4,iso9660
    Hi there! This system is managed by puppet. (defaults.yaml)


    Is it possible to use a fact that contains multiple values within hiera?
    If so, what am I missing? If not, what's the point of having facts with
    multiple values in the first place?

    Facter was designed before hiera. It serves a larger purpose than just
    usage as hiera hierarchy conditionals.

    Do I understand correctly that your custom fact which "spits out a list of
    server types" returns more than 1 item in a comma separated list like the
    filesystems example you provided?

    Looking at the nature of this custom fact would it not be better if it
    provided a single 'server type'? If this is impossible, you could split the
    fact into X facts and (servertype1,servertype2 and servertype3) which could
    then be used nicely in hiera.

    If your custom fact is outputting a highly variable string (that looks like
    multiple values due to a comma), then it's not really suitable to use in
    hiera.yaml I believe.


    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/193db15f-c47b-4838-a2de-03b98d7395d1%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Paul Archer at Dec 12, 2013 at 2:20 pm

    On Wednesday, December 11, 2013 11:03:33 PM UTC-6, William Leese wrote:


    Facter was designed before hiera. It serves a larger purpose than just
    usage as hiera hierarchy conditionals.

    I get that.
    Do I understand correctly that your custom fact which "spits out a list of
    server types" returns more than 1 item in a comma separated list like the
    filesystems example you provided?

    Exactly. I used the filesystems example for simplicity (you can try it
    without setting up a custom fact), and because it has exactly the same
    behavior as my target fact.


    Looking at the nature of this custom fact would it not be better if it
    provided a single 'server type'? If this is impossible, you could split the
    fact into X facts and (servertype1,servertype2 and servertype3) which could
    then be used nicely in hiera.

    To make this work in hiera I'd need a hierarchy like:
       - "groups/%{servertype1}"
       - "groups/%{servertype2}"
       - "groups/%{servertype3}"

    It's clunky, but the more I think about it, the more I think that's the
    only way to do this. I just realized that hiera doesn't have any way to
    iterate over the list handed to it from facter. So if my servertype fact is
    equal to git,ntp,ldap (for example), then I can't expect hiera to do a
    lookup with the fact servertype set to git, then another lookup with the
    fact servertype set to ntp, etc. I think it's reasonable to *want* this
    behavior, but it's not what it does (for now, at least).

    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/408ffd33-88c2-424c-b80d-4c462fd5185b%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedDec 11, '13 at 10:33p
activeDec 12, '13 at 2:20p
posts3
users2
websitepuppetlabs.com

2 users in discussion

Paul Archer: 2 posts William Leese: 1 post

People

Translate

site design / logo © 2022 Grokbase