Ask Your Question
0

How to use hiera variable in Exec with onlyif or unless condition

asked 2015-07-17 11:23:34 -0500

rgv gravatar image

Hi,

Is there a way to use hiera variable in Exec with onlyif or unless condition?

ex:

class createfile () {
  $create_file = hiera('create_file','false')

  file { '/tmp/mydir':
      ensure  =>  directory,
      owner   =>  "root",
      group   =>  "root",
      mode    =>  755,
      **onlyif  =>  [$create_file, true],**
  }
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-19 22:23:13 -0500

DarylW gravatar image

Hello!

You should be able to use the value returned from hiera in a conditional around the file resource.

class createfile () {
  $create_file = hiera('create_file','false')
  if $create_file {
    file { '/tmp/mydir':
      ensure  =>  directory,
      owner   =>  "root",
      group   =>  "root",
      mode    =>  755,
    }
  }
}
edit flag offensive delete link more
0

answered 2015-07-20 03:29:20 -0500

The exec's onlyif is expected to be an external command so this won't work.

This should work however:

class create file() {
  $create_file = hiera('create_file', 'false')

  if $create_file {
    file { '/tmp/mydir':
      ensure  => directory,
      owner   => 'root',
      group   => 'root',
      mode    => '0755',
    }
  }
}
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-07-17 11:23:34 -0500

Seen: 791 times

Last updated: Jul 20 '15