I am trying to implement valdiate cmd attribute in the concat fragment but unable to get desire result.
Overall goal is after the concatenation of files, execute valdiate_cmd which is basically validation for file order 01 (tls_cert_file1) if the script returns 0 then deploy concat files otherwise stop the further action.
In the below manifest, Problem is validation (valdiate_cmd) performs first then concatenation of files, but my requirement is to first finish the concatenation of files then execute valdiate_cmd, reason is first fetching changes from the source concat it then run validation. Basically validation is only for tls_cert_file1. Problem with this is first validation perform with existing cert which is already in the client and returns 0 then concatenation happening which found changes in the source.
# 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',
}
I tried validation attribute in concat fragmenet, but it seems concat::fragment not parameter for valdiate_cmd.
error: Error: Could not retrieve catlog from remote server. Evaluation Error: while evaluating a Resource Statement, concat::fragment { 'tls_cert_file1': has no parameter 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',
}
Not plausible. It's not how validation works in puppetlabs/concat. The provided
validate_cmdparameter is ultimately used to configure aFileresource, which has this effect:The "new content" in this case is that obtained by concatenating the fragments. (It can't be anything else, because that's what the File must install to satisfy its specifications.)
Puppet cannot and does not execute the validation command before concatenating the fragments. You should be asking yourself, however: if the new content is validated before being put into place, then how can the validation script know where to find it? The
Filedocs go on to answer that:That is, your script must accept the name of the file to validate as a command-line argument, and the command string associated with the
validate_cmdparameter must contain a%as a placeholder to tell Puppet where in the command to insert that filename.