Skip to content

Commit a2ea259

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

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Diff for: 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.

Diff for: 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+
}

Diff for: tasks/submit_csr.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
14+
if majver < 6
15+
conf = %x{puppet config print dns_alt_names certname}
16+
.chomp
17+
.split("\n")
18+
.map {|line| line.split(' = ') }
19+
.to_h
20+
21+
cmd = ['/opt/puppetlabs/bin/puppet', 'certificate', 'generate',
22+
'--ca-location', 'remote',
23+
'--dns-alt-names', conf['dns_alt_names'],
24+
conf['certname']
25+
]
26+
else
27+
cmd = ['/opt/puppetlabs/bin/puppet', 'ssl', 'submit_request']
28+
end
29+
30+
stdout, status = Open3.capture2(*cmd)
31+
puts stdout
32+
if status.success?
33+
exit 0
34+
else
35+
exit 1
36+
end
37+
end
38+
39+
main

0 commit comments

Comments
 (0)