Ask Your Question
0

having issue with test in exec

asked 2015-03-04 11:33:43 -0500

Chutki gravatar image

Hi,

I have issue with below code, the manifests does not run exec resource if I use test option

exec { test:
  path => '/etc',
  command => "/bin/sed -i 's/comment$id/#comment$id/g' /etc/services',
  onlyif => "test `grep  comment$id /etc/services` -eq 0"
}

If I run with without test in onlyif then exec resoruce will execute correctly.

onlyif => "test `grep  comment$id /etc/services` -eq 0"

if the value (comment$id) is existing without any comment line then the exec resourc should start, that is my intention for onlyif condition

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-03-04 15:33:38 -0500

tsheriffk gravatar image

updated 2015-03-04 15:34:49 -0500

I am trying to figure out exactly what you are doing(so i may have misinterpreted what you are trying to accomplish), but if this is a specific line starting with "comment$id" why not just use the file_line directive of stdlib instead?

  file_line { 'comment id' :
  line     => '#comment$id',
  path     => '/etc/services',
  match    => '^comment$id',
  }

otherwise i believe if you use the exec as shown in your example, change your onlyif line to:

onlyif   => '/bin/grep ^comment$id /etc/services'
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

Stats

Asked: 2015-03-04 11:33:43 -0500

Seen: 75 times

Last updated: Mar 04 '15