Ask Your Question
0

Exec with onlyif and bash if statement

asked 2017-09-06 05:32:54 -0600

nextshellid gravatar image

Hello, I'd like to make the below onlyif work as expected. Due to certain dependencies I can't use file resource to ensure the contents of one file into an other.

  exec { 'apply_new_cert':
    command => "cat /some/file > /other/file",
    onlyif  => "if [[ `cat /some/file` == `cat /other/file` ]]; then exit 0 ; else exit 1; fi;",
    require => Exec['new_cert'],
    path    => ['/bin', '/usr/bin', '/sbin', '/usr/sbin', '/usr/loca/bin','],
  }

The error I get is " Could not evaluate: Could not find command 'if'", I haven't found much documentation in how onlyif works and all the guesses I've tried so far have failed. Please feel free to suggest other options however I'd still like to know the correct syntax to implement the existing onlyif statement.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-06 09:32:06 -0600

DarylW gravatar image

You would set the provider attribute to shell

https://docs.puppet.com/puppet/latest...

exec { 'apply_new_cert':
  command => "cat /some/file > /other/file",
  onlyif  => "if [[ `cat /some/file` == `cat /other/file` ]]; then exit 0 ; else exit 1; fi;",
  require => Exec['new_cert'],
  path    => ['/bin', '/usr/bin', '/sbin', '/usr/sbin', '/usr/loca/bin','],
  provider => 'shell',
}
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

Stats

Asked: 2017-09-06 05:32:54 -0600

Seen: 93 times

Last updated: Sep 06