Ask Your Question

file_line doesn't work

asked 2014-11-03 03:36:41 -0600

Chutki gravatar image


I have written below block to replace sed "s/1024/14567/" limit.conf > limit.bkup from soft nproc 14567 test file

file_line { 'update': ensure => present, path => '/etc/files/limit.conf', line => '1024', match => '^14567', }

I am getting below error message "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter"

Also some one please help me out to understand better in file_line resource. I always facing issue in match and line. I know the concept but when I implement in code its throwing some error. I am trying all the possibilities, but until i post in forum I am unable to resolve the issue.

NOTE: I should not use exec resource sed and auges the project.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-03 13:08:44 -0600

cbarbour gravatar image

updated 2014-11-03 13:11:11 -0600

The file_line type source code is enlightening in this case.

if (self[:match])
    raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter")

In English, the regex you supply using the match argument must be a positive match for the value you're writing into the file.

One of the two following examples should solve your problem.

This example declares that soft nproc should == 14567 no matter it's current value.

file_line { 'limit soft nproc 14567': 
  ensure => present,
  path => '/etc/files/limit.conf',
  line => 'soft nproc 14567',
  match => '^soft nproc',

Note that soft nproc 14567 ~= /^soft nproc/

This solution declares that soft nproc 1024 shouldn't be in the file, and soft nproc 14567 should be in the file.

file_line { 'limit soft nproc 1024': 
  ensure => 'absent',
  path => '/etc/files/limit.conf',
  line => 'soft nproc 1024',

file_line { 'limit soft nproc 14567': 
  ensure => 'present',
  path => '/etc/files/limit.conf',
  line => 'soft nproc 14567',

The first solution is much better. In the 2nd solution, if soft nproc is set to something other than 1024, that setting will remain in limits.conf and a new entry for 14567 will be created.

Remember: file_line is designed to manipulate entire lines, it's not a general string replacement tool. This is in keeping with puppet's declarative model. Your original example attempts to be procedural.

edit flag offensive delete link more


Well thats just great. How is anyone supposed to be able to replace strings then?? There is a reason why people DO need this capability you know.

solarflow99 gravatar imagesolarflow99 ( 2015-02-16 01:27:21 -0600 )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: 2014-11-03 03:36:41 -0600

Seen: 3,178 times

Last updated: Nov 03 '14