Ask Your Question

augeas not idomponent in onlyif match

asked 2015-03-04 11:15:31 -0500

Chutki gravatar image


I have below manifests

define lim_def($item=$title,$value){
    augeas { $title:
      lens  => 'limits.lns',
      incl  => '/etc/security/limits.conf',
      changes  => ["set domain[last()+1] @test",
                   "set domain[last()]/type  soft",
                   "set domain[last()]/item  $item",
                   "set domain[last()]/value $value",
                   "set domain[last()+1] @test",
                   "set domain[last()]/type  hard",
                   "set domain[last()]/item  $item",
                   "set domain[last()]/value $value",],
      onlyif => "match domain[domain = '@test'][item = '${item}'] size == 0",

though I added onlyif condition with matching the augeas is not behaving like idomponent.

If I run the manifests it should print the below o/p

for eg


If I run it again it is again appending the same data


but I want this as an one time activity. is there any wrong with my match condition

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-04 19:05:50 -0500

GregLarkin gravatar image

I strongly suggest that you have a look at this Puppet Forge module to manage the limits.conf file. I installed it and wrote the following Puppet code:

class { 'limits':
  config => {
    '@test' => {
      'locks' => {
        soft => '10',
        hard => '10',
  use_hiera => false,

I have now applied that Puppet manifest to my server multiple times, and the lines are only added to limits.conf once:

# End of file
@test soft locks 10
@test hard locks 10

It's really simple, and I think it will help you avoid subtle problems with using the augeas resource directly.

edit flag offensive delete link more


Thanks, I downloaded this module but I dont understand the below lines "defnode node service-name[.='${service_name}'][protocol = '${protocol}'] ${service_name}", "set \$node/port ${port}", i know defnode but how service_name replace it. also what is \$node why they use slash

Chutki gravatar imageChutki ( 2015-04-28 05:30:54 -0500 )edit

I haven't looked at the source of the module, but I don't expect you would need to in order to use it. service_name, protocol and port all look like Puppet variables that are probably defined in the file where that code appears.

GregLarkin gravatar imageGregLarkin ( 2015-04-29 12:39:06 -0500 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2015-03-04 11:15:31 -0500

Seen: 222 times

Last updated: Mar 04 '15