Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exec command unless directory exists in puppet

Tags:

ruby

puppet

How to exec a command if directory does not exists in puppet file?

exec { "my_exec_task":
  command => "tar zxf /home/user/tmp/test.tar.gz",
  unless => "test -d /home/user/tmp/new_directory",
  path    => "/usr/local/bin/:/bin/",
}

I get error: "Could not evaluate: Could not find command 'test'". Also is this the best practice to check if directory does not exists?

like image 450
TroodoN-Mike Avatar asked Mar 21 '23 15:03

TroodoN-Mike


2 Answers

test work for me at /usr/bin, so adding it to path could solve error.

unless => 'bash -c "test -d /home/user/tmp/new_directory"',

Should work too. But I think the correct way is to use creates:

exec { "my_exec_task":
  command => "tar zxf /home/user/tmp/test.tar.gz",
  creates => "/home/user/tmp/new_directory",
  path    => "/usr/local/bin/:/bin/",
}
like image 197
Raul Andres Avatar answered Mar 29 '23 09:03

Raul Andres


Actual problem is in path: path => [ '/usr/local/bin', '/sbin', '/bin', '/usr/sbin', '/usr/bin' ]

like image 20
Anup Singh Avatar answered Mar 29 '23 09:03

Anup Singh