# file_line resource match problems

Hi,

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 test 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

edit retag close merge delete

Sort by » oldest newest most voted

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?

more

Thanks jonn. It worked

more