2

I'm using puppet and augeas tool quite a lot to configure property files. My latest requirement is to apply the same fixed set of changes to quite a long list of property files. So, I would like to do it in one run, and not to write an augeas for each property file.

Example:

  augeas { 'change_name_whatever':
    lens    => 'a_customized_lens',
    incl    => "$path/file1.properties", 
    changes => $change_set,
  }
  augeas { 'change_name_whatever':
    lens    => 'a_customized_lens',
    incl    => "$path/file2.properties", 
    changes => $change_set,
  }
etc...

I would like to use:

  augeas { 'change_name_whatever':
    lens    => 'a_customized_lens',
    incl    => "[list of files to change], 
    changes => $change_set,
  }

but it's not possible since augeas needs to pre-load the file.

Since I am using puppet 3.8, I can't use foreach type of looping. I saw that in puppet 4 you can declare a list of files, and then loop on them and do your thing. Which is cool... but doesn't work in puppet 3.

So, do I have any other solution then copy/pasting the same code many times?

cheers.

1 Answer 1

5

The best option to achieve that is to create a defined resource type:

define customized::filetype ($change_set) {
 augeas { "customized filetype ${title}":
    lens    => 'a_customized_lens',
    incl    => $name, 
    changes => $change_set,
  }
}

and then use it with an array in the title:

customized::filetype { [
  "$path/file1.properties",
  "$path/file2.properties"
  ]:
  change_set => $change_set,
}

You could even (and I'd recommend it) abstract the change set as key/value parameters in the defined resource type. For example:

define customized::filetype ($key, $value) {
 augeas { "customized filetype ${title}":
    lens    => 'a_customized_lens',
    incl    => $name, 
    changes => "set ${key} ${value}",
  }
}
5
  • looks promising. I'm going to give it a try, thx.
    – bioShark
    Jan 12, 2016 at 11:36
  • what do you mean by abstracting the change set? For me $change_set is an array with multiple strings like: 'set key value'
    – bioShark
    Jan 12, 2016 at 11:40
  • Man that worked like a charm! Great many thanks :)
    – bioShark
    Jan 12, 2016 at 11:56
  • @bioShark I added an example of abstracting the change set.
    – raphink
    Jan 12, 2016 at 13:50
  • @Raphink Aha, got it. My change set is actually an array of multiple "set key values". Your example is a generic one where only one change has to be made. But it's great, either way, thanks
    – bioShark
    Jan 12, 2016 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .