Ask Your Question

file_line resource match problems

asked 2014-10-31 06:16:08 -0500

Chutki gravatar image

updated 2014-10-31 07:55:59 -0500

llowder gravatar image


I have written sample test file in file_line resource

class dummy::test1{
file_line {'test_file':
  ensure  => present,
  path    => 'dummy/manifests/test',
  line    => 'aaa   bbb   ccc   ddd',
  match   => '^.*aaa.*fer.*$'

below is the target file to change the value

888   999   000   3245
aaa   fer   sss   ddd
vvv   333   dec   bcd
cdf   sw3   fff   dss

I want to change second row value to replace with line => 'aaa bbb ccc ddd',

I tried all the below possibilities

match => '^.*aaa.*fer.*$'
match => '^ aaa  fer  sss   ddd'
match => '^ aaa  fer  sss   ddd$'
match => '^ .*aaa .*fer .*sss.*ddd$'
match => 'aaa  fer  sss   ddd'

but none of the match is working I am getting the below error

Validation of File_line[test_file] failed: When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter at /modules/dummy/manifests/test.pp:8

please help me out

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-11-01 04:09:57 -0500

jonn gravatar image

Yeah, this seems a bit like a bug to me. As the error message suggests, the match parameter has to match against the line that you want to add. This works OK for a limited use case (e.g. where you have a file with 'key=value' pairs or something) but it doesn't seem to be a very general purpose solution. Plus, it doesn't jive with the documentation.

For now I think you're stuck with something like:

match => '^aaa\s+'

but you'll be out of luck if there's another line in the file with that same prefix :(

If you can't manage the file in its entirety, maybe you'd have more luck with something like Augeas?

edit flag offensive delete link more

answered 2014-11-02 22:26:54 -0500

Chutki gravatar image

Thanks jonn. It worked

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


Asked: 2014-10-31 06:16:08 -0500

Seen: 10,714 times

Last updated: Nov 02 '14