Ask Your Question
0

How should I structure my hiera for systemd limits?

asked 2017-11-20 11:13:10 -0600

Red Cricket gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-11-23 09:23:05 -0600

stivesso gravatar image

updated 2017-11-23 09:28:19 -0600

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...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-11-20 11:13:10 -0600

Seen: 31 times

Last updated: Nov 23