Cross-module variables and mix-and-match with Hiera

65 views
Skip to first unread message

Kimo Rosenbaum

unread,
Sep 19, 2014, 4:45:17 PM9/19/14
to puppet...@googlegroups.com
Hello,

I'm using puppet 3 with roles (mostly), profiles, and Hiera. I have a profile setup (for pdxcat/collectd) to, amongst other things, hiera_array() for values [of localports] to pass on to collectd::plugin::tcpconns. Defining everything in hiera files works as expected. However, I would like to add to those values from other profiles. But I haven't been able to get that working. Any suggestions?

If the below text isn't displaying properly I've also created a gist: https://gist.github.com/kimor79/b0cdd99cb98c01892049

Thanks
Kimo

hiera.yaml (condensed):
  ---
  :hierarchy:
    - roles/%{role}
    - common

hiera/roles/app-db.yaml:
  ---
  classes:
    - profiles::postgresql::server

  # This works as expected:
  # profiles::collectd::tcpconns_localports:
  #    - 5432

hiera/common.yaml:
  ---
  classes:
    - profiles::collectd

  profiles::collectd::tcpconns_localports:
    - 22

profiles/manifests/collectd.pp:
  class profiles::collectd {

    # This is an array lookup so multiple hiera files can add ports to watch.
    $tcpconns_localports  = hiera_array('profiles::collectd::tcpconns_localports')
    $tcpconns_remoteports = hiera_array('profiles::collectd::tcpconns_remoteports')

    # NOTE: If you need to pass "false" onto the collectd config make sure to
    # quote the false (foo => 'false') as some templates only do a simple if
    # statement (if @foo) which when foo is undef evaluates to false.

    class { '::collectd':
      purge        => true,
      purge_config => true,
      recurse      => true,
    }
  
    class { '::collectd::plugin::tcpconns':
      listening     => 'false',
      localports   => $tcpconns_localports,
      remoteports => $tcpconns_remoteports,
    }
  }

profiles/manifests/postgresql/server.pp:
  class profiles::postgresql::server {
    class { '::postgresql::server': }
  
    # I would like to be able to add this here so I don't have to remember to
    # add it to every %{::role}.yaml which includes this class.
    # $::profiles::collectd::tcpconns_localports += [ '5432' ]
  }

jcbollinger

unread,
Sep 22, 2014, 11:06:42 AM9/22/14
to puppet...@googlegroups.com


On Friday, September 19, 2014 3:45:17 PM UTC-5, Kimo Rosenbaum wrote:
Hello,

I'm using puppet 3 with roles (mostly), profiles, and Hiera. I have a profile setup (for pdxcat/collectd) to, amongst other things, hiera_array() for values [of localports] to pass on to collectd::plugin::tcpconns. Defining everything in hiera files works as expected. However, I would like to add to those values from other profiles. But I haven't been able to get that working. Any suggestions?



I don't think its possible to approach the problem as you are trying to do.  Even if you could, you shouldn't create cross-profile dependencies like you are trying to do.  Instead, it is the job of the role to provide everything needed to integrate all the profiles.  You could do it via the role class instead of in Hiera, however.  That makes sense to me, because the role classes are where the information of which profiles are involved is stored.

Perhaps you could add a parameter to profiles::collectd by which the role can provide the needed data, which it would assemble from class variables of the profile classes.


John

Reply all
Reply to author
Forward
0 new messages