Skip to content

Commit da54935

Browse files
committed
Make CSR submission version-aware
So that Puppet 5 (PE 2018.1) can be supported.
1 parent ac60e63 commit da54935

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

plans/action/install.pp

+1-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@
288288
)
289289

290290
# Ensure certificate requests have been submitted
291-
run_command(@(HEREDOC), $agent_installer_targets)
292-
/opt/puppetlabs/bin/puppet ssl submit_request
293-
| HEREDOC
291+
run_task('peadm::submit_csr', $agent_installer_targets)
294292

295293
# TODO: come up with an intelligent way to validate that the expected CSRs
296294
# have been submitted and are available for signing, prior to signing them.

tasks/submit_csr.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"description": "Submit a certificate signing request",
3+
"parameters": { },
4+
"input_method": "stdin",
5+
"implementations": [
6+
{"name": "submit_csr.rb"}
7+
]
8+
}

tasks/submit_csr.rb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
2+
#
3+
# rubocop:disable Style/GlobalVars
4+
require 'json'
5+
require 'open3'
6+
7+
def main
8+
params = JSON.parse(STDIN.read)
9+
majver = %x{/opt/puppetlabs/bin/puppet --version}
10+
.chomp
11+
.split('.')
12+
.first
13+
.to_i
14+
15+
if majver < 6
16+
conf = %x{puppet config print dns_alt_names certname}
17+
.chomp
18+
.split("\n")
19+
.map {|line| line.split(' = ') }
20+
.to_h
21+
22+
cmd = ['/opt/puppetlabs/bin/puppet', 'certificate', 'generate',
23+
'--ca-location', 'remote',
24+
'--dns-alt-names', conf['dns_alt_names'],
25+
conf['certname']
26+
]
27+
else
28+
cmd = ['/opt/puppetlabs/bin/puppet', 'ssl', 'submit_request']
29+
end
30+
31+
stdout, status = Open3.capture2(*cmd)
32+
puts stdout
33+
if status.success?
34+
exit 0
35+
else
36+
exit 1
37+
end
38+
end
39+
40+
main

0 commit comments

Comments
 (0)