How should I structure my hiera for systemd limits?

I am trying to use https://github.com/camptocamp/puppet-.... I want to setup some systemd limits for a service so I have included ...

include ::systemd


... in my manifest. And I have this hiera data:

systemd::service_limits:
'openstack-nova-compute.service':
limits:
LimitNOFILE: 32768


But when puppet on my node I get this error:

Error while evaluating a Function Call, Class[Systemd]: parameter 'service_limits' unrecognized key 'openstack-nova-compute.service' at ...


I have looked at the docs and they do not explain how to form the hash in hiera, they just give this example:

::systemd::service_limits { 'foo.service':
limits => {
'LimitNOFILE' => 8192,
'LimitNPROC'  => 16384,
}
}


So how would I do that in hiera/yaml?

edit retag close merge delete

Sort by » oldest newest most voted

Hi Red Cricket,

Two Issues I found when looking at that Issue.

The first Issue is that you are trying to have Automatic parameter lookups with Defined types, and I am not sure that this is supported. If you check here, systemd::service_limits is a defined type, and my advise to have this in hiera is to Use lookup() coupled with iteration with each.

The second Issue is coming from the camptocamp/puppet-systemd code. In facts, systemd::service_limits refers both to a parameter name (in init.pp) and to a Defined Type Name (service_limits.pp) that also include systemd. That caused great confusion when you set systemd::service_limits in your hiera configuration (the automatic parameters lookup interprets systemd::service_limits as the parameter that is set in init.pp).

Anyway, the simple workaround to solve these Issues is to rename the hiera key to another name and use lookup() function and iteration with each (as seen below) to create the needed resources:

I am also opening an Issue with camptocamp/puppet-systemd to see if they can rename the systemd::service_limits parameters...

Below is a working piece of Code/Hiera Configuration....

Code:
Note that I used profiles::myservices::service_limits as Hiera key to avoid the second Issue...

  lookup('profiles::myservices::service_limits', Hash, 'first', {}).each | $resource_title,$params| {
::systemd::service_limits {
# Give the defaults so you do not have to set these the same for
# every user in your hiera data
default:
limits => {'LimitNOFILE' => 8192, 'LimitNPROC'  => 16384,};

# Set all parameters from values in the hash
# (The '* =>' construct "splats" everything in the $params hash) #$resource_title: * => \$params ;
}
}


Hiera:

---
profiles::myservices::service_limits:
'openstack-nova-compute.service':
limits:
LimitNOFILE: 32768
LimitNPROC:  32768


I hope I was of some help...

more