- 论坛徽章:
- 0
|
回复 3# 关阴月飞
试了不行,存在的文件去找standard.erb,不存在的文件直接报错提示模版文件不存在
问题已经解决了,我自己定义了一个函数去判断文件是否存在,然后返回不同值,然后配置文件里再去做判断就可以了
自定义exist函数,文件存在返回0,不存在返回1- Puppet::Parser::Functions::newfunction(:exist, :type => :rvalue) do |vals|
- key = vals[0]
- result = []
- key.each do |file|
- if File.exists?(file)
- result << 0
- else
- result << 1
- end
- end
- return result.join(" ")
- end
复制代码 配置文件里的设置- $myvar = exist("/puppet/modules/test/templates/${hostname}.erb")
- if $myvar == 0 {
- $mark = $hostname
- }
- else {
- $mark = Standard
- }
- file {
- "test":
- mode => 644, owner => root, group => root,
- ensure => present,
- name => "/tmp/test.txt",
- content => template("test/${mark}.erb");
- }
复制代码 |
|