根据Puppet中文件的存在应用不同的配置

问题描述 投票:0回答:1

我想在Puppet清单中添加一个功能,以在存在另一个文件时应用一个配置,如果不存在则应应用其他配置。我已经尝试过这部分代码:

    exec { "chk_file_exist":
    path    =>  ["/usr/bin","/usr/sbin", "/bin"],
    onlyif  => "test -f ${file} && echo 0",
    before => File['/etc/systemd/system/config1.service'],
   }

   exec { "chk_file_doesnt_exist":
    path    =>  ["/usr/bin","/usr/sbin", "/bin"],
    onlyif  => "test ! -f ${file} && echo 0",
    refreshonly => true,
    before => File['/etc/systemd/system/config2.service'],
   }

   file { '/etc/systemd/system/config1.service':
       content => template('module/service/config1.service'),
       require => Exec["chk_file_exist"],
   }

   file { '/etc/systemd/system/config2.service':
       content => template('module/service/config2.service'),
       require => Exec["chk_file_doesnt_exist"],
      } 

它仅创建一个文件,但会引发错误:

Error: Could not find command 'chk_file_exist'
Error: /Stage[main]/mymodule::service/Exec[chk_file_exist]/returns: change from 'notrun' to ['0'] failed: Could not find command 'chk_file_exist' (corrective)

如何避免此错误?

谢谢

file exec puppet
1个回答
0
投票

由于没有为exec资源赋予command属性,因此出现该错误。一个exec resource defaults to using its name as a command

尝试以下类似的操作,它使用exec作为不执行任何操作的命令。

true
© www.soinside.com 2019 - 2024. All rights reserved.