TroodoN-Mike
TroodoN-Mike

Reputation: 16175

exec command unless directory exists in 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?

Upvotes: 4

Views: 6707

Answers (2)

Anup Singh
Anup Singh

Reputation: 323

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

Upvotes: 1

Raul Andres
Raul Andres

Reputation: 3806

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/",
}

Upvotes: 6

Related Questions