Ask Your Question

Variable scoping in hiera config

asked 2015-09-08 08:34:26 -0600

johan kielbaey gravatar image


We're using Puppet 3.7.2 with hiera 1.3.4. We have implemented the role/profile pattern as is recommended. In the profiles we do hiera lookups.

The value for certain configuration parameters depend on the role in which they are used. (eg. the size of the file system containing oracle binaries is 5GB for Oracle clients (role: oracleclient), while it is 20GB on Oracle DB servers (role:oracledb)).

Below our hiera config:

:backends: yaml
    :datadir: /etc/puppet/environments/%{::environment}/hieradata
:logger: puppet
    - nodes/%{::fqdn}
    - roles/%{role}/%{::environment}
    - roles/%{role}
    - network_zones/%{::network_zone}
    - environments/%{::environment}
    - common

The above only works when %{role} is defined in the node definition (see snippet below), but that's redundant and not guaranteed to work properly. If someone forgets to set $role in a new node definition, the proper values will not be used and the server will be misconfigured. So I'm looking for a way to have this variable to set another way.

node 'dbserver' {
  $role = ‘oracle_db’
  include ::role::oracle::server::db

class role::oracle::server::db {

It's not recommended to use local puppet variable in hiera, so defining $role in the role class is not a good idea. So what is the recommended way to solve this problem?

Thanks a lot! Johan

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-09-08 13:49:39 -0600

We resolve this by setting the $role as an external fact on each system at provisioning time. The node's role class is then discovered in the site.pp according to the value of $role, and if this fact is undefined (or doesn't match a role in site.pp) then we fail() the run.

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: 2015-09-08 08:34:26 -0600

Seen: 169 times

Last updated: Sep 08 '15