Skip to content

Commit 40c691b

Browse files
AaronShannonCoMfUcIoS
authored andcommitted
PE-38768 classify compilers task added (#467)
1 parent d848dbe commit 40c691b

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

Diff for: REFERENCE.md

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* [`backup_classification`](#backup_classification): A task to call the classification api and write to file
5757
* [`cert_data`](#cert_data): Return certificate data related to the Puppet agent
5858
* [`cert_valid_status`](#cert_valid_status): Check primary for valid state of a certificate
59+
* [`classify_compilers`](#classify_compilers): Classify compilers as legacy or non-legacy
5960
* [`code_manager`](#code_manager): Perform various code manager actions
6061
* [`code_sync_status`](#code_sync_status): A task to confirm code is in sync accross the cluster for clusters with code manager configured
6162
* [`divert_code_manager`](#divert_code_manager): Divert the code manager live-dir setting
@@ -1056,6 +1057,20 @@ Data type: `String`
10561057

10571058
The certifcate name to check validation of
10581059

1060+
### <a name="classify_compilers"></a>`classify_compilers`
1061+
1062+
Classify compilers as legacy or non-legacy
1063+
1064+
**Supports noop?** false
1065+
1066+
#### Parameters
1067+
1068+
##### `compiler_hosts`
1069+
1070+
Data type: `Array[String]`
1071+
1072+
List of FQDNs of compilers
1073+
10591074
### <a name="code_manager"></a>`code_manager`
10601075

10611076
Perform various code manager actions

Diff for: manifests/setup/legacy_compiler_group.pp

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
],
3333
classes => {
3434
'puppet_enterprise::profile::master' => {
35-
'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ },
35+
'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ },
3636
'puppetdb_port' => [8081],
3737
},
3838
},
@@ -54,7 +54,7 @@
5454
],
5555
classes => {
5656
'puppet_enterprise::profile::master' => {
57-
'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ },
57+
'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_a_pool_address].filter |$_| { $_ },
5858
'puppetdb_port' => [8081],
5959
},
6060
},
@@ -69,4 +69,4 @@
6969
node_group { 'PE Compiler':
7070
rule => ['and', ['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'false']],
7171
}
72-
}
72+
}

Diff for: manifests/setup/node_manager.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
],
254254
classes => {
255255
'puppet_enterprise::profile::master' => {
256-
'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ },
256+
'puppetdb_host' => [$internal_compiler_a_pool_address].filter |$_| { $_ },
257257
'puppetdb_port' => [8081],
258258
},
259259
},

Diff for: tasks/classify_compilers.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"description": "Classify compilers as legacy or non-legacy",
3+
"parameters": {
4+
"compiler_hosts": {
5+
"type": "Array[String]",
6+
"description": "List of FQDNs of compilers"
7+
}
8+
},
9+
"implementations": [
10+
{
11+
"name": "classify_compilers.rb",
12+
"requirements": ["shell"]
13+
}
14+
]
15+
}

Diff for: tasks/classify_compilers.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'json'
4+
require 'open3'
5+
6+
def classify_compiler(services)
7+
if services.any? { |service| service['type'] == 'puppetdb' }
8+
:non_legacy
9+
else
10+
:legacy
11+
end
12+
end
13+
14+
params = JSON.parse(STDIN.read)
15+
compiler_hosts = params['compiler_hosts']
16+
17+
legacy_compilers = []
18+
non_legacy_compilers = []
19+
20+
compiler_hosts.each do |compiler|
21+
cmd = "puppet infra status --host #{compiler} --format=json"
22+
stdout, stderr, status = Open3.capture3(cmd)
23+
24+
if status.success?
25+
services = JSON.parse(stdout)
26+
classification = classify_compiler(services)
27+
28+
if classification == :legacy
29+
legacy_compilers << compiler
30+
else
31+
non_legacy_compilers << compiler
32+
end
33+
else
34+
STDERR.puts "Error running command for #{compiler}: #{stderr}"
35+
end
36+
end
37+
38+
result = {
39+
'legacy_compilers' => legacy_compilers,
40+
'compilers' => non_legacy_compilers
41+
}
42+
43+
puts result.to_json

0 commit comments

Comments
 (0)