joe*_*joe 5 linux unix redhat puppet
如果目录存在,我正在尝试编写它创建文件的模块,否则它不应该做任何事情。
class puppetmodule{
exec { 'chk_dir_exists':
command => 'test -d /usr/dir1',
path => ["/usr/bin","/usr/sbin", "/bin"],
} ->
file {'usr/dir1/test.txt':
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0750',
}
}
Run Code Online (Sandbox Code Playgroud)
下面是它抛出的错误。请就此给我建议。
错误:test -d /usr/dir1 返回 1 而不是 [0] 之一
Puppet 是关于最终状态的。您可以确保文件以您指定的状态存在或不存在。如果您需要执行一些分支(if)逻辑,Puppet 也支持。请参阅文档中的条件 - https://puppet.com/docs/puppet/latest/lang_conditional.html
$directory_exists = <insert logic here>
if $directory_exists {
file {'usr/dir1/test.txt':
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0750',
}
}
Run Code Online (Sandbox Code Playgroud)