我正在尝试在 concat 片段中实现 valdiate cmd 属性,但无法获得所需的结果。
总体目标是在文件串联之后,执行 valdiate_cmd ,这基本上是对文件顺序 01 (tls_cert_file1) 的验证,如果脚本返回 0,则部署串联文件,否则停止进一步操作。
在下面的清单中,问题是首先执行验证(valdiate_cmd),然后执行文件串联,但我的要求是首先完成文件串联,然后执行 valdiate_cmd,原因是首先从源中获取更改并连接它,然后运行验证。基本上验证仅针对 tls_cert_file1。 问题是首先使用客户端中已有的证书执行验证并返回 0,然后发生串联,发现源中发生了更改。
# Verification script
file { 'tls_verification_script':
ensure => file,
path => "${config}/tls_verification",
owner => 'nagios',
group => 'nagios',
content => template('nagios/tls_verification.erb'),
}
# Concatenation of certificates
concat { 'tls_cert':
ensure => present,
path => $tls_path,
owner => 'nagios',
group => 'nagios',
validate_cmd => "/usr/bin/python3 ${config}/tls_verification",
}
# Fragment for tls_cert_file1
concat::fragment { 'tls_cert_file1':
target => 'tls_cert',
source => "puppet:///module/xxxxxxxxxxxx",
order => '01',
}
# Fragment for tls_cert_file2
concat::fragment { 'tls_cert_file2':
target => 'tls_cert',
source => "puppet:///modules/xxxxxxxxxxxx",
order => '02',
}
我尝试了 concat fragmenet 中的验证属性,但似乎 concat::fragment 不是 valdiate_cmd 的参数。
错误: 错误:无法从远程服务器检索catlog。评估错误:评估资源语句时,concat::fragment { 'tls_cert_file1': has noparameter named 'valdiate_cmd'
# Verification script
file { 'tls_verification_script':
ensure => file,
path => "${config}/tls_verification",
owner => 'nagios',
group => 'nagios',
content => template('nagios/tls_verification.erb'),
}
# Concatenation of certificates
concat { 'tls_cert':
ensure => present,
path => $tls_path,
owner => 'nagios',
group => 'nagios',
}
# Fragment for tls_cert_file1
concat::fragment { 'tls_cert_file1':
target => 'tls_cert',
source => "puppet:///module/xxxxxxxxxxxx",
order => '01',
validate_cmd => "/usr/bin/python3 ${config}/tls_verification",
}
# Fragment for tls_cert_file2
concat::fragment { 'tls_cert_file2':
target => 'tls_cert',
source => "puppet:///modules/xxxxxxxxxxxx",
order => '02',
}
在下面的清单中,问题是首先执行验证(valdiate_cmd),然后执行文件串联
不合理。这不是 puppetlabs/concat 中验证的工作方式。提供的
validate_cmd
参数最终用于配置 a File
资源,有这样的效果:
用于在替换文件之前验证文件语法的命令。如果 Puppet 由于新的
或source
需要重写文件,它会首先检查新内容的有效性。如果验证失败,文件资源将失败。content
本例中的“新内容”就是通过片段拼接得到的内容。 (不能是其他任何东西,因为这是文件必须安装的内容才能满足其规范。)
Puppet 在连接片段之前不能也不会执行验证命令。然而,您应该问自己:如果新内容在投入到位之前经过验证,那么验证脚本如何知道在哪里可以找到它?
File
文档继续回答这个问题:
此命令必须具有完全限定的路径,并且应在预期输入文件的位置包含百分比 (
) 标记。如果语法正确,它必须退出%
,否则非零。应用目录时,该命令将在目标系统上运行,而不是在主 Puppet 服务器上运行。0
也就是说,您的脚本必须接受要验证的文件名作为命令行参数,并且与
validate_cmd
参数关联的命令字符串必须包含 %
作为占位符,以告诉 Puppet 在命令中的位置插入该文件名。