Ask Your Question

file_line skip commented line in user limit file

asked 2015-05-08 05:52:42 -0500

Chutki gravatar image

updated 2015-05-08 05:55:45 -0500


I have the following code for limits manifests

file_line { 'app_limit_90-nofiles':
      path  => '/etc/security/limits.d/90-nofiles.conf',
      match => '^*  hard    nofiles',
      line  => '*          hard    nofiles    500'

below is my 90-nofiles.con file

*          soft    nofiles     123
#*          hard    nofiles    500

so if i run the manifests it is skipping this commented line #* hard nofiles 500 and getting below o/p

 *          soft    nofiles     123
  *          hard    nofiles    500

what my doubt is, the file_line resource will skip if the line is commented.

Also I hard coded the value in "line" attribute, is it possible to do it by hiera or any variable instead of using the value in manifests.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-08 11:58:07 -0500

JohnsonEarls gravatar image

updated 2015-05-11 23:42:36 -0500

First part of question: Your match line specifies which lines will be replaced. Since you anchored to the beginning of the line with ^, it should not catch the # comment. However, it might also not catch a line that begins with * - depending on how puppet's regular expressions are compiled. To be completely sure, you should escape (\) the * in your match line. You might also want to allow for any amount of whitespace between the *, the hard, and the nofiles keywords:

    match => '^\*[ \t]+hard[ \t]+nofiles' ,

Second part of your question: Just use a variable interpolation in the line and that variable can be assigned in any manner you like, whether from hiera directly via a hiera() lookup or through automatic parameter lookups for a parameterized class. To do this, you have to use a "-quoted string instead of the '-quoted string you're using now:

    line  => "*          hard    nofiles    ${open_files_limit}"

The two ways to get the value from hiera: Direct lookup...

$open_files_limit = hiera('open_files_limit', '500')

or automatic parameter lookup in a parameterized class:

class foo ($open_files_limit = 500) {
edit flag offensive delete link more


I tried "match => '^\*[ \t]+*hard[ \t]+nofiles' ," it worked. But getting warning when compile" /var/opt/lib/pe-puppet/lib/puppet/type/file_line.rb:64: warning: nested repeat operator + and * was replaced with '*': /^\*[ \t]+*hard[ \t]+nofiles/" had look at ruby but no clue what it does.

Chutki gravatar imageChutki ( 2015-05-11 23:34:52 -0500 )edit

My apologies - I've removed the extra `*` after the +.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-05-11 23:43:04 -0500 )edit

Impeccable :)

Chutki gravatar imageChutki ( 2015-05-12 06:24:56 -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

1 follower


Asked: 2015-05-08 05:52:42 -0500

Seen: 343 times

Last updated: May 11 '15