The exec command if the directory does not exist in the puppet

How to execute a command if the directory does not exist in the doll 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 the error: “Failed to evaluate: could not find the command“ test. ”Is it also best to check if the directory exists?

+4
source share
2 answers

testworks for me in /usr/bin, so adding it to a path might solve the error.

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

Should also work. 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/",
}
+5
source

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

+1

Source: https://habr.com/ru/post/1526041/


All Articles