Puppet Environments with Hiera

106 views
Skip to first unread message

Mark Rosedale

unread,
Nov 4, 2014, 10:33:06 AM11/4/14
to puppet...@googlegroups.com
So I'm setting up puppet environments. This is what I have in my puppet.conf under the [master] section
environmentpath = $confdir/environments



Now if I set environment inside the puppet.conf it will grab the environment I have set up ($confdir/environments/test), but if I set it in hiera it seems to ignore it completely, what is really odd is that it compiles a catalog, so it does work, but it is clearly not compiling the correct catalog, since I have a notify in my site.pp to let me know which environment it ran out of. 

If I set the following in a hiera file I should expect puppet environments to work correct? 

environment: 'test'

Any ideas how I can trace what catalog it is compiling? Or why it seems to be ignoring hiera? 

jcbollinger

unread,
Nov 5, 2014, 9:28:42 AM11/5/14
to puppet...@googlegroups.com


On Tuesday, November 4, 2014 9:33:06 AM UTC-6, Mark Rosedale wrote:
So I'm setting up puppet environments. This is what I have in my puppet.conf under the [master] section
environmentpath = $confdir/environments



Now if I set environment inside the puppet.conf it will grab the environment I have set up ($confdir/environments/test), but if I set it in hiera it seems to ignore it completely,


As it should.  A node's environment is determined by the first of these that applies:
  1. the environment specified for the node by an ENC;
  2. the environment requested by the agent, as directed by its local configuration or command-line argument;
  3. the general default environment specified in the master's configuration;
  4. "production" if no environment is otherwise indicated.
Hiera plays no part in the determination.

 
what is really odd is that it compiles a catalog, so it does work, but it is clearly not compiling the correct catalog, since I have a notify in my site.pp to let me know which environment it ran out of. 


I don't see what's odd about that.  Whatever environment is chosen (probably "production") has a node block that matches the target node, or perhaps has no node blocks at all.  If there isn't a node block specifically for that node's name, then it could perhaps be matched to a regex node block or a default node block.

 

If I set the following in a hiera file I should expect puppet environments to work correct? 

environment: 'test'



You should not expect that to make Puppet choose the "test" environment for any nodes, if that's what you mean.  If you want the master to control to which environment each node is assigned, overriding any environment requested by the node, then you need an ENC.  If you generally want to rely on node blocks for node classification (which is in no way bad), then the ENC doesn't need to do much beyond beyond assigning environments.

 
Any ideas how I can trace what catalog it is compiling? Or why it seems to be ignoring hiera? 



It is ignoring hiera for this purpose because it should.  If you still want to probe what the master is doing then you can find the node's catalog cached on the node if you want to examine it after the fact.  You might get additional information by running the master with --debug output enabled.  You can put notice() calls and Notify resources in your manifests, too.


John

Mark Rosedale

unread,
Nov 5, 2014, 9:48:01 AM11/5/14
to puppet...@googlegroups.com
Sorry I guess I was confused I thought Hiera is an ENC...am I wrong about that? 

jcbollinger

unread,
Nov 6, 2014, 9:17:28 AM11/6/14
to puppet...@googlegroups.com


On Wednesday, November 5, 2014 8:48:01 AM UTC-6, Mark Rosedale wrote:
Sorry I guess I was confused I thought Hiera is an ENC...am I wrong about that? 


Yes, you are wrong.  Hiera is an external data service with special Puppet integration, not an ENC.  Hiera can be used to serve almost all the same purposes as an ENC, albeit by different means, but assigning nodes to environments is one ENC function that Hiera cannot serve.

You can find out more about ENCs here: https://docs.puppetlabs.com/guides/external_nodes.html.


John

jcbollinger

unread,
Nov 6, 2014, 9:21:18 AM11/6/14
to puppet...@googlegroups.com


On Thursday, November 6, 2014 8:17:28 AM UTC-6, jcbollinger wrote:

Hiera is an external data service with special Puppet integration, not an ENC.


That turns out to be very important, by the way, because a master can have only one ENC configured at a time.  Masters that use an ENC do not thereby foreclose the possibility of using Hiera.


John

R.I.Pienaar

unread,
Nov 6, 2014, 9:27:58 AM11/6/14
to puppet-users
should be pretty simple to write a node indirector that fetches the environment from hiera :)

not sure if that would still allow node blocks to be used in addition but to replace
the usual node default { include(hiera_array("klasses")) } should be real easy to do
which would then support setting the environment too.
Reply all
Reply to author
Forward
0 new messages