|
31 | 31 | )
|
32 | 32 | } else {
|
33 | 33 | run_command('systemctl stop puppet.service', $agent_target)
|
| 34 | + # If re-using a node which was previously part of the infrastructure then it |
| 35 | + # might have a bad configuration which will prevent it from reconfiguring. Best |
| 36 | + # example of this is a failed primary being added back into infrastructure as |
| 37 | + # a replica |
34 | 38 | out::message('Ensuring node is set to query current primary for Puppet Agent operations')
|
35 | 39 | run_command("/opt/puppetlabs/bin/puppet config set --section main server ${primary_target.peadm::certname()}", $agent_target)
|
36 | 40 | run_command('/opt/puppetlabs/bin/puppet config delete --section agent server_list', $agent_target)
|
|
43 | 47 | # Obtain data about certificate from agent
|
44 | 48 | $certdata = run_task('peadm::cert_data', $agent_target).first.value
|
45 | 49 |
|
| 50 | + # The invalid status is primarily serves as a way to catch revoked certificates. |
| 51 | + # A primary server is the only thing that can reliably identify if agent |
| 52 | + # certificates are revoked, if it is then skip the submit and sign process and |
| 53 | + # just got directly to forcing a regeneration. |
46 | 54 | if ($certstatus['certificate-status'] == 'invalid') {
|
47 | 55 | $force_regenerate = true
|
48 | 56 | $skip_csr = true
|
49 | 57 | } else {
|
| 58 | + # When the primary can't validate a certificate because it is missing but the |
| 59 | + # agent claims it has one, clean the agent to get to an agreed upon state |
| 60 | + # before moving onto the submit and sign process. |
50 | 61 | if $certdata['certificate-exists'] and $certstatus['reason'] =~ /The private key is missing from/ {
|
51 | 62 | out::message("Agent: ${agent_target.peadm::certname()} has a local cert but Primary: ${primary_target.peadm::certname()} does not, force agent clean")
|
52 | 63 | run_task('peadm::ssl_clean', $agent_target, certname => $agent_target.peadm::certname())
|
|
68 | 79 | run_task('peadm::sign_csr', $primary_target, { 'certnames' => [$agent_target.peadm::certname()] } )
|
69 | 80 | }
|
70 | 81 |
|
| 82 | + # If agent certificate is good but lacks appropriate extensions, plan will still |
| 83 | + # regenerate certificate |
71 | 84 | run_plan('peadm::modify_certificate', $agent_target,
|
72 | 85 | primary_host => $primary_target.peadm::certname(),
|
73 | 86 | add_extensions => $certificate_extensions,
|
|
0 commit comments