Ask Your Question
0

Exec with onlyif and bash if statement

asked 2017-09-04 10:51:03 -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-04 11:59:52 -0600

nextshellid gravatar image

Update, all its need is to add the attribute provider => 'shell', and switch the exit codes.

edit flag offensive delete link more

Comments

Wow, that's much better than what I've done... onlyif => 'bash -c "if.... "',

DarylW gravatar imageDarylW ( 2017-09-04 23:22:11 -0600 )edit

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: 2017-09-04 10:51:03 -0600

Seen: 144 times

Last updated: Sep 04