Trying to understand hiera and use in site.pp

96 views
Skip to first unread message

Courtney Campbell

unread,
Jun 1, 2016, 12:16:56 PM6/1/16
to Puppet Users
I just upgraded to puppet 3.8. Things I used to do in 3.7 like import and inherits no longer work. Anyway, I have been trying to figure out hiera. The docs on the site are great if you already know what you are doing. Anyway, I have environments setup. And have the hiera.yaml setup and working. Here is the hiera.yaml.

---
:backends:
  - yaml
:yaml:
  :datadir: "/etc/puppet/environments/%{::environment}/hieradata"
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - "%{::osfamily}/%{::operatingsystemmajrelease}"
  - "virtual/%{::virtual}"
  - "common"


under my development einvironment I have

RedHat/6.yaml
RedHat/7.yaml

6.yaml has info for ntp and 7.yaml has info for chrony.

6.yaml
---
ntp::restrict: 127.0.0.1
ntp::service_enable: true
ntp::service_ensure: running
ntp::servers:
  - ntp.server.com

7.yaml
---
chrony::service_enable: true
chrony::service_ensure: running
chrony::servers:
  - ntp.server.com

That all looks fine and hiera test works.
$ hiera ntp::service_enable ::environment=development ::osfamily=RedHat ::operatingsystemmajrelease=6
true

Now I am unsre how to make use of this in  my site.pp.

I have this, but it is not working:

if $operatingsystemmajrelease =~ '6' {
   include ntp
}
elsif $operatingsystemmajrelease == '7' {
   include chrony
}

It's setting the ntp.conf and chrony.conf files to the defaults. I really like puppet when it is working. But trying to figure this out is just pissing me off. I wish there was a doc that would hold my hand and just give exact examples on how to get this to work. It's not intuitive.






Rob Nelson

unread,
Jun 1, 2016, 12:58:26 PM6/1/16
to puppet...@googlegroups.com
Can you show what happens on a brand new CentOS 6 or 7 node when you run `puppet agent -t`? It should work the way you expect, though the service_enable and service_ensure settings match the default, so there won't be that much different.

If it is working, but the output isn't clear on that, you could try running puppet against it as is, then turn one of the service_* values to false/stopped and you should see the state change. If it changes from running to stopped, and back again if you revert the changes, you know things are working. If not, it gets you closer to the issue.

--
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/62c54869-4f91-449f-bf31-3f720db862ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Courtney Campbell

unread,
Jun 1, 2016, 2:14:15 PM6/1/16
to Puppet Users
It does work, but it is not taking the setting in 6.yaml. It is setting the defaults.

Courtney Campbell

unread,
Jun 1, 2016, 2:19:59 PM6/1/16
to Puppet Users
Nor does it take the settings on a 7 server. Just sets the defaults of the module.

Rob Nelson

unread,
Jun 1, 2016, 3:49:23 PM6/1/16
to puppet...@googlegroups.com
"Works" in this case would mean that when you set ntp::service_enable: false, on the next puppet run, the service would be disabled. If that's the case, hiera is working and any errors are likely to do with typos or yaml formatting issues with the other settings.
Reply all
Reply to author
Forward
0 new messages