<\/p>\n\r\nnode default {\r\n include users::common\r\n include users::production\r\n include users::dc1\r\n}\r\n<\/pre>\n<\/code><\/p>\n
I’ve made this trivial in Hiera now, given the 3 files below:<\/p>\n
common.json<\/b>
\n<\/p>\n{\"classes\":\"users::common\"}<\/pre>\n<\/code><\/p>\n
production.json<\/b>
\n<\/p>\n{\"classes\":\"users::production\"}<\/pre>\n<\/code><\/p>\n
dc1.json<\/b>
\n<\/p>\n{\"classes\":\"users::dc1\"}<\/pre>\n<\/code><\/p>\n
And appropriate Hiera hierarchy configuration you can achieve this using the node block below:<\/p>\n
<\/p>\n\r\nnode default {\r\n hiera_include(\"classes\")\r\n}\r\n<\/pre>\n<\/code><\/p>\n
Any parametrized classes that use Hiera as in my previous post will simply do the right thing. Individual classes<\/em> variables can be arrays so you can include many classes at each tier. Now just add a role<\/em> fact on your machines, add a role tier in Hiera and you’re all set.<\/p>\nThe huge win here is that you do not need to do any stupid hacks like load the facts from the Puppet Masters vardir in your ENC to access the node facts or any of the other hacky things people do in ENCs. This is simply a manifest doing what manifests do – just better.<\/p>\n
The hiera<\/em> CLI tool has been updated with array support, here is it running on the data above:<\/p>\n<\/p>\n\r\n$ hiera -a classes\r\n[\"users::common\"]\r\n$ hiera -a classes environment=production location=dc1\r\n[\"users::common\", \"users::production\", \"users::dc1\"]\r\n<\/pre>\n<\/code><\/p>\n
I’ve also added a hiera_array()<\/i> function that takes the same parameters as the hiera()<\/i> function but that returns an array of the found data. The array capability will be in Hiera version 0.2.0 which should be out later today.<\/p>\n
I should also mention that Luke Kanies took a quick stab at integrating Hiera into Puppet and the result is pretty awesome. Given the example below Puppet will magically use Hiera if it’s available, else fall back to old behavior.<\/p>\n
<\/p>\n\r\nclass ntp::config($ntpservers=\"1.pool.ntp.org\") {\r\n .\r\n .\r\n}\r\n\r\nnode default {\r\n include ntp::config\r\n}\r\n<\/pre>\n<\/code><\/p>\n
With Lukes proposed changes this would be equivalent to:
\n<\/p>\n\r\nclass ntp::config($ntpservers=hiera(\"ntpservers\", \"1.pool.ntp.org\")) {\r\n .\r\n .\r\n}\r\n<\/pre>\n<\/code><\/p>\n
This is pretty awesome. I wouldn’t hold my breath to see this kind of flexibility soon in Puppet core but it shows whats possible.<\/p>\n","protected":false},"excerpt":{"rendered":"
Note: This project is now being managed by Puppetlabs, its new home is http:\/\/projects.puppetlabs.com\/projects\/hiera Last week I posted the first details about my new data source for Hiera that enables its use in Puppet. In that post I mentioned I want to do merge or array searches in the future. I took a first stab […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[1],"tags":[121,85,97,21,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/2142"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=2142"}],"version-history":[{"count":14,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/2142\/revisions"}],"predecessor-version":[{"id":2152,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/2142\/revisions\/2152"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=2142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=2142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=2142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}