File tree Expand file tree Collapse file tree 7 files changed +66
-0
lines changed Expand file tree Collapse file tree 7 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 64
64
* [ ` download ` ] ( #download ) : Download a file using curl
65
65
* [ ` enable_replica ` ] ( #enable_replica ) : Execute the enable replica puppet command
66
66
* [ ` filesize ` ] ( #filesize ) : Return the size of a file in bytes
67
+ * [ ` get_group_rules ` ] ( #get_group_rules ) : Run on a PE primary node to return the rules currently applied to the PE Infrastructure Agent group
67
68
* [ ` get_peadm_config ` ] ( #get_peadm_config ) : Run on a PE primary node to return the currently configured PEAdm parameters
68
69
* [ ` get_psql_version ` ] ( #get_psql_version ) : Run on a PE PSQL node to return the major version of the PSQL server currently installed
69
70
* [ ` infrastatus ` ] ( #infrastatus ) : Runs puppet infra status and returns the output
@@ -1185,6 +1186,12 @@ Data type: `String`
1185
1186
1186
1187
Path to the file to return the size of
1187
1188
1189
+ ### <a name =" get_group_rules " ></a >` get_group_rules `
1190
+
1191
+ Run on a PE primary node to return the rules currently applied to the PE Infrastructure Agent group
1192
+
1193
+ ** Supports noop?** false
1194
+
1188
1195
### <a name =" get_peadm_config " ></a >` get_peadm_config `
1189
1196
1190
1197
Run on a PE primary node to return the currently configured PEAdm parameters
Original file line number Diff line number Diff line change 261
261
# the existing groups are correct enough to function until the upgrade is
262
262
# performed.
263
263
if (versioncmp($pe_version , ' 2019.7.0' ) >= 0) {
264
+ $rules = run_task(' peadm::get_group_rules' , $primary_target ).first.value[' _output' ]
265
+ $rules_formatted = stdlib::to_json_pretty(parsejson($rules ))
266
+ out::message("WARNING: The following existing rules on the PE Infrastructure Agent group will be overwritten with default values:\n ${rules_formatted} " )
267
+
264
268
apply($primary_target ) {
265
269
class { 'peadm::setup::node_manager_yaml':
266
270
primary_host => $primary_target .peadm::certname(),
Original file line number Diff line number Diff line change 326
326
default => $primary_postgresql_target .peadm::certname(),
327
327
}
328
328
329
+ $rules = run_task(' peadm::get_group_rules' , $primary_target ).first.value[' _output' ]
330
+ $rules_formatted = stdlib::to_json_pretty(parsejson($rules ))
331
+ out::message("WARNING: The following existing rules on the PE Infrastructure Agent group will be overwritten with default values:\n ${rules_formatted} " )
332
+
329
333
apply($primary_target ) {
330
334
class { 'peadm::setup::node_manager_yaml':
331
335
primary_host => $primary_target .peadm::certname(),
Original file line number Diff line number Diff line change 20
20
21
21
expect_task ( 'peadm::cert_data' ) . return_for_targets ( 'primary' => trustedjson )
22
22
expect_task ( 'peadm::read_file' ) . always_return ( { 'content' => '2021.7.9' } )
23
+ expect_task ( 'peadm::get_group_rules' ) . return_for_targets ( 'primary' => { '_output' => '{"rules": []}' } )
23
24
24
25
# For some reason, expect_plan() was not working??
25
26
allow_plan ( 'peadm::modify_certificate' ) . always_return ( { } )
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ def allow_standard_non_returning_calls
22
22
23
23
it 'minimum variables to run' do
24
24
allow_standard_non_returning_calls
25
+ expect_task ( 'peadm::get_group_rules' ) . return_for_targets ( 'primary' => { '_output' => '{"rules": []}' } )
25
26
26
27
expect_task ( 'peadm::read_file' )
27
28
. with_params ( 'path' => '/opt/puppetlabs/server/pe_build' )
@@ -36,6 +37,7 @@ def allow_standard_non_returning_calls
36
37
37
38
it 'runs with a primary, compilers, but no replica' do
38
39
allow_standard_non_returning_calls
40
+ expect_task ( 'peadm::get_group_rules' ) . return_for_targets ( 'primary' => { '_output' => '{"rules": []}' } )
39
41
40
42
expect_task ( 'peadm::read_file' )
41
43
. with_params ( 'path' => '/opt/puppetlabs/server/pe_build' )
@@ -92,6 +94,7 @@ def allow_standard_non_returning_calls
92
94
. always_return ( { 'content' => installed_version } )
93
95
94
96
expect_task ( 'peadm::cert_data' ) . return_for_targets ( 'primary' => trusted_primary )
97
+ expect_task ( 'peadm::get_group_rules' ) . return_for_targets ( 'primary' => { '_output' => '{"rules": []}' } )
95
98
end
96
99
97
100
it 'updates pe.conf if r10k_known_hosts is set' do
Original file line number Diff line number Diff line change
1
+ {
2
+ "description" : " Run on a PE primary node to return the rules currently applied to the PE Infrastructure Agent group" ,
3
+ "parameters" : { },
4
+ "input_method" : " stdin"
5
+ }
Original file line number Diff line number Diff line change
1
+ #!/opt/puppetlabs/puppet/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'puppet'
7
+
8
+ # GetInfrastructureAgentGroupRules task class
9
+ class GetInfrastructureAgentGroupRules
10
+ def execute!
11
+ infrastructure_agent_group = groups . find { |obj | obj [ 'name' ] == 'PE Infrastructure Agent' }
12
+ if infrastructure_agent_group
13
+ puts JSON . pretty_generate ( infrastructure_agent_group [ 'rule' ] )
14
+ else
15
+ puts JSON . pretty_generate ( { 'error' => 'PE Infrastructure Agent group does not exist' } )
16
+ end
17
+ end
18
+
19
+ def groups
20
+ net = https ( 4433 )
21
+ res = net . get ( '/classifier-api/v1/groups' )
22
+ JSON . parse ( res . body )
23
+ end
24
+
25
+ def https ( port )
26
+ https = Net ::HTTP . new ( Puppet . settings [ :certname ] , port )
27
+ https . use_ssl = true
28
+ https . cert = OpenSSL ::X509 ::Certificate . new ( File . read ( Puppet . settings [ :hostcert ] ) )
29
+ https . key = OpenSSL ::PKey ::RSA . new ( File . read ( Puppet . settings [ :hostprivkey ] ) )
30
+ https . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
31
+ https . ca_file = Puppet . settings [ :localcacert ]
32
+ https
33
+ end
34
+ end
35
+
36
+ # Run the task unless an environment flag has been set, signaling not to. The
37
+ # environment flag is used to disable auto-execution and enable Ruby unit
38
+ # testing of this task.
39
+ unless ENV [ 'RSPEC_UNIT_TEST_MODE' ]
40
+ Puppet . initialize_settings
41
+ GetInfrastructureAgentGroupRules . new . execute!
42
+ end
You can’t perform that action at this time.
0 commit comments