Using yaml to create custom array fact

115 views
Skip to first unread message

Mark Rosedale

unread,
Aug 28, 2014, 10:33:47 AM8/28/14
to puppet...@googlegroups.com
Hello,

So I'm using stlib with the /etc/facter/facts.d/ to set up some custom facts of some of my nodes. What I want to do is use yaml to set an array in facter that will then get interpreted by Hiera. 

Let me give an example. I have the following hierarchy. 
:hierarchy:
  - "node/%{::fqdn}"
  - "cust/%{::cust}"
  - "role/%{::role}"
  - base

I can set the cust fact and that should just be one customer. But the role may not be. So what I'd like to do is set the role fact to be an array and have that interpreted by hiera. Is this possible? 

Brian Wilkins

unread,
Aug 28, 2014, 11:28:54 AM8/28/14
to puppet...@googlegroups.com
I would actually put role higher than node simply because you will assign the common role parameters first and then node specific parameters last. This is how I do it in my hiera.yaml:

---
:backends:
  - yaml
:hierarchy:
  - common
  - "role/%{::system_role}"
  - node/%{::fqdn}
  - "%{environment}"
  - global

:yaml:
  :datadir: /etc/puppet/data

then in my common.yaml:

classes:
  - profiles::common

profiles::nagios_resource::hostgroups: %{::system_role}

profiles::nagios_resource::allowed_hosts:
  - '127.0.0.1'
  - 'hostname'
  - 'hostname'

profiles::logstash::brokers:
  - ip
  - ip

profiles::nagios_resource::connection_to_redis_check::check_host:
  - 'hostname'
  - 'hostname'

profiles::collectd::graphite_host: 'hostname'
profiles::collectd::graphite_port: '2103'

Then I auto assign my roles using facter:

/etc/puppet/modules/roles/lib/facter/system_role.rb

Facter.add(:system_role) do
  setcode do
    host = Facter.value(:fqdn)
    declared_role = Facter.value(host)
    declared_role.nil? ? 'general' : declared_role
  end
end

Under /etc/puppet/modules/roles/files/system_role_fact.yaml

---
host1: admin
host2: servicemix
host3: logstash_indexer
etc

Felix Frank

unread,
Aug 28, 2014, 11:31:59 AM8/28/14
to puppet...@googlegroups.com
On 08/28/2014 04:33 PM, Mark Rosedale wrote:
>
> I can set the cust fact and that should just be one customer. But the
> role may not be. So what I'd like to do is set the role fact to be an
> array and have that interpreted by hiera. Is this possible?

There have been pull requests to that effect, but it was determined that
this feature was too dangerous to put in. You could quickly be looking
at severe performance impacts from larger arrays of roles.
Reply all
Reply to author
Forward
0 new messages