nhuff / chef-augeas

chef augeas provider
Apache License 2.0
12 stars 0 forks source link

Got some issues with run_if #12

Closed nicutor closed 6 years ago

nicutor commented 6 years ago

Hi,

I have this file /root/tmp

# comment sample 1
# comment sample 2
line 1 value # comment line 1
line 2 value # comment line 2
Include /some/file
Include /some/other/file

I am trying to add a new line on it, only if that line doesn't exist using:

augeas 'include_some_file' do
  changes ['ins 01 before /files/root/tmp/1', 'set /files/root/tmp/01 Include /some/file']
  lens 'Simplelines.lns'
  incl '/root/tmp'
  run_if  "match /files/root/tmp[count(*[. = 'Include /some/file']) = 0]"
end

and I get this error:

NoMethodError
-------------
undefined method `strip' for nil:NilClass

I've also tried:

run_if  "match /files/root/tmp[count(*[. = 'Include /some/file']) = 0] == 0"
run_if  "get /files/root/tmp[count(*[. = 'Include /some/file']) = 0] == 0"
...

The command

match /files/root/tmp[count(*[. = 'Include /some/file']) = 0]

runs well, I just don't know how to compare it to get a return code for run_if

Can you please guide me on the right direction?

Thank you.

nicutor commented 6 years ago

The correct way is this:

augeas 'include_some_file' do
  changes ['ins 01 before /files/root/tmp/1', 'set /files/root/tmp/01 Include /some/file']
  lens 'Simplelines.lns'
  incl '/root/tmp'
  run_if  "match /files/root/tmp/*[. = 'Include /some/file'] size == 0"
end

Thanks to @lutter