file - 根据 Puppet 中文件的存在应用不同的配置
问题描述
如果另一个文件存在,我想在 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)
我怎样才能避免这个错误?
谢谢
解决方案
您收到该错误是因为您没有为exec
资源赋予command
属性。资源默认使用exec
其标题作为命令。
尝试以下类似的操作,它true
用作不执行任何操作的命令。
exec { "chk_file_exist":
command => 'true',
path => ["/usr/bin","/usr/sbin", "/bin"],
onlyif => "test -f ${file} && echo 0",
before => File['/etc/systemd/system/config1.service'],
}
推荐阅读
- javascript - 如何滑动滑块鼠标悬停分页
- c# - 为什么我的归并排序算法不能正确排序我的数组?
- c# - 来自更新存储过程的 Linq to sql 未处理异常
- javascript - 启动 jQuery 脚本在放置在控制台时有效,但在放置到站点代码时无效
- monetdb - 从 Monetdb 中的表中获取所有列
- abap - 标准的深度嵌套数据类型?
- artificial-intelligence - 什么时候算法被认为是人工智能?
- r - 使用 eigenstrat 进行血统调整的方法
- javascript - 如何在 VueJs 中通过路由名称获取特定的路由数据?
- php - 如何使用来自ajax的get方法仅将html代码的文本部分`(不包括标签)`传递给php页面