hiera with environments

67 views
Skip to first unread message

solarflow 99

unread,
Jun 9, 2020, 1:46:13 AM6/9/20
to Puppet Users
I have this strange problem where I just upgraded from puppetserver 5.5 to 6, and now the 2nd environment doesn't see hiera values, but the production environment does.  I wonder if top level lookups don't work anymore?  Here's how I have it configured:


Here's my directory layout:

code
└── environments
    ├── preprod
    │   ├── environment.conf
    │   ├── gitclone
    │   │   └── production
    │   │       ├── hieradata
    │   │       │   ├── common.yaml
    │   │       │   └── nodes
    │   │       ├── manifests
    │   │       │   ├── nodes.pp
    │   │       │   └── site.pp
    │   │       └── modules
    └── production
        ├── hieradata
        │   ├── common.yaml
        │   └── nodes
        ├── manifests
        │   ├── nodes.pp
        │   └── site.pp
        └── modules






/etc/puppetlabs/puppet:

$ cat hiera.yaml
---
version: 5
defaults:
  # The default value for "datadir" is "data" under the same directory as the hiera.yaml
  # file (this file)
  # When specifying a datadir, make sure the directory exists.
  # See https://puppet.com/docs/puppet/latest/environments_about.html for further details on environments.
  # datadir: data
  # data_hash: yaml_data

  datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
  data_hash: yaml_data


hierarchy:
  - name: "Per-node data (yaml version)"
    path: "nodes/%{::trusted.certname}.yaml"
  - name: "Other YAML hierarchy levels"
    paths:
      - "common.yaml"





/etc/puppetlabs/code/environments/preprod:


$ ls -la
total 4
drwxr-xr-x  3 root root  62 Jun  8 21:44 ./
drwxr-xr-x. 4 root root  39 Jun  8 14:33 ../
-rw-r--r--  1 root root 142 Jun  8 14:38 environment.conf
drwxr-xr-x  3 root root  24 Jun  8 14:36 gitclone/
lrwxrwxrwx  1 root root  29 Jun  8 21:44 hierdata -> gitclone/production/hieradata/





$ cat environment.conf
manifest = $codedir/environments/preprod/gitclone/production/manifests
modulepath = $codedir/environments/preprod/gitclone/production/modules





 
$ cat hierdata/common.yaml
---
infraserver:             'bigmachine.local'




$ cat site.pp

$infraserver          = hiera( 'infraserver' )




But the clients don't see it in preprod, failing their puppet runs, and the codebase is exactly the same:

Error 500 on SERVER: Server Error: Function lookup() did not find a value for the name 'infraserver' on node dev1.local


$ puppet lookup infraserver --environment production --node dev1.local
--- bigmachine.local
 
$ puppet lookup infraserver --environment preprod --node dev1.local


Martin Alfke

unread,
Jun 11, 2020, 4:54:13 AM6/11/20
to puppet...@googlegroups.com
Hi,

You should change to using a control-repo and adopt your codebase.

We recommend (assuming you use a git based control-repo and r10k or PE code manager for deployment):

1. Copy your global hiera.yaml file (etc/puppetlabs/puppet/hiera.yaml) to each of your environments.
2. Remove global hiera.yaml file
3. Just use data or hieradata as datadir. Not the complete path.
4. Use relative paths in your environment.conf file
5. Instead of having different hieradata per environment we recommend to add an environment hierarchy.

You can also separate your hieradata from control-repo and make them an individual git repo.
In this case you can add hieradata as a module to your puppet file and change the path in hiera.yaml file.

You can find examples on how to achieve this in our Puppet Infrastructure Construction Kit (https://github.com/example42/psick)
Here we deploy the same branch name - when existing on hieradata repo - and fall back to master branch.

Hth,
Martin


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a0655c3e-9b5e-4097-a793-60f3117df82do%40googlegroups.com.

solarflow 99

unread,
Jun 11, 2020, 1:45:36 PM6/11/20
to Puppet Users
hi, thanks for the reply.  This is all for PE, but i'm using puppet 6 OSS..

It used to work this way in 5.5 too, so I don't understand why its not seeing hiera in the preprod environment.  I could always do this:

- make changed in preprod, and git commit there
- cd to prod, then:
- git remote update,
- git merge --ff-only preprod/master
- cd back to preprod, then
- git pull
To unsubscribe from this group and stop receiving emails from it, send an email to puppet...@googlegroups.com.

Nick Bertrand

unread,
Jun 11, 2020, 2:06:22 PM6/11/20
to puppet...@googlegroups.com
Hi,

Perhaps it was just a typo in the email, but it looks like there might be a typo in one of your filenames:

lrwxrwxrwx  1 root root  29 Jun  8 21:44 hierdata -> gitclone/production/hieradata/

Should this have been 'hieradata' instead of 'hierdata'?

Nick

solarflow 99

unread,
Jun 11, 2020, 3:05:34 PM6/11/20
to Puppet Users
dohh!  I can't believe I didn't even notice that.... darn typo,

thats all it was too, its working fine now.  Thanks a lot for pointing that out!  Hopefully this example might help someone else out at least.

I should have seen that...

Bart-Jan Vrielink

unread,
Jun 12, 2020, 3:16:26 AM6/12/20
to puppet...@googlegroups.com

Hello,


Control Repo and R10K work fine with Puppet OSS and is the recommended architecture for using multiple environments with Puppet.


PE Code Manager is indeed only for PE, but in most cases is just a fancy name for R10K.


lrwxrwxrwx  1 root root  29 Jun  8 21:44 hierdata -> gitclone/production/hieradata/
$ cat environment.conf
manifest = $codedir/environments/preprod/gitclone/production/manifests
modulepath = $codedir/environments/preprod/gitclone/production/modules





 
$ cat hierdata/common.yaml
---
infraserver:             'bigmachine.local'




$ cat site.pp

$infraserver          = hiera( 'infraserver' )




But the clients don't see it in preprod, failing their puppet runs, and the codebase is exactly the same:

Error 500 on SERVER: Server Error: Function lookup() did not find a value for the name 'infraserver' on node dev1.local


$ puppet lookup infraserver --environment production --node dev1.local
--- bigmachine.local
 
$ puppet lookup infraserver --environment preprod --node dev1.local



--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a0655c3e-9b5e-4097-a793-60f3117df82do%40googlegroups.com.


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/88343dbe-0818-49b8-85be-bad4ee8e7963o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages