Skip to content

Commit 7af69e7

Browse files
committed
(puppetlabs#469) Assign correct environment to node groups
1 parent 4a27e2d commit 7af69e7

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.8
1+
3.0.7

REFERENCE.md

+19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [`peadm::file_or_content`](#peadm--file_or_content)
3030
* [`peadm::flatten_compact`](#peadm--flatten_compact)
3131
* [`peadm::generate_pe_conf`](#peadm--generate_pe_conf): Generate a pe.conf file in JSON format
32+
* [`peadm::get_node_group_environment`](#peadm--get_node_group_environment): check if a custom PE environment is set in pe.conf
3233
* [`peadm::get_pe_conf`](#peadm--get_pe_conf)
3334
* [`peadm::get_targets`](#peadm--get_targets): Accept undef or a SingleTargetSpec, and return an Array[Target, 1, 0]. This differs from get_target() in that: - It returns an Array[Target
3435
* [`peadm::migration_opts_default`](#peadm--migration_opts_default)
@@ -715,6 +716,24 @@ Data type: `Hash`
715716
A hash of settings to set in the config file. Any keys that are set to
716717
undef will not be included in the config file.
717718

719+
### <a name="peadm--get_node_group_environment"></a>`peadm::get_node_group_environment`
720+
721+
Type: Puppet Language
722+
723+
check if a custom PE environment is set in pe.conf
724+
725+
#### `peadm::get_node_group_environment(Target $primary)`
726+
727+
The peadm::get_node_group_environment function.
728+
729+
Returns: `Any`
730+
731+
##### `primary`
732+
733+
Data type: `Target`
734+
735+
the FQDN for the primary, here we will read the pe.conf from
736+
718737
### <a name="peadm--get_pe_conf"></a>`peadm::get_pe_conf`
719738

720739
Type: Puppet Language
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# @summary check if a custom PE environment is set in pe.conf
3+
#
4+
# @param primary the FQDN for the primary, here we will read the pe.conf from
5+
#
6+
# @see https://www.puppet.com/docs/pe/latest/upgrade_pe#update_environment
7+
#
8+
# @author Tim Meusel <[email protected]>
9+
#
10+
function peadm::get_node_group_environment(Target $primary) {
11+
$peconf = peadm::get_pe_conf($primary)
12+
# if both are set, they need to be set to the same value
13+
# if they are not set, we assume that the user runs their infra in production
14+
$pe_install = $peconf['pe_install::install::classification::pe_node_group_environment']
15+
$puppet_enterprise = $peconf['puppet_enterprise::master::recover_configuration::pe_environment']
16+
17+
# check if both are equal
18+
# This also evaluates to true if both are undef
19+
if $pe_install == $puppet_enterprise {
20+
if $pe_install =~ String[1] {
21+
return $pe_install
22+
} else {
23+
return 'production'
24+
}
25+
} else {
26+
fail("pe_install::install::classification::pe_node_group_environment and puppet_enterprise::master::recover_configuration::pe_environment need to be set to the same value, not '${pe_install}' and ${puppet_enterprise}")
27+
}
28+
}

manifests/setup/node_manager.pp

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# A load balancer address directing traffic to any of the "B" pool
2424
# compilers. This is used for DR configuration in large and extra large
2525
# architectures.
26+
# @param environment the environment that will be assigned to all the PE Infra node groups
2627
#
2728
class peadm::setup::node_manager (
2829
String[1] $primary_host,
@@ -36,6 +37,7 @@
3637
Optional[String[1]] $compiler_pool_address = undef,
3738
Optional[String[1]] $internal_compiler_a_pool_address = $server_a_host,
3839
Optional[String[1]] $internal_compiler_b_pool_address = $server_b_host,
40+
String[1] $environment = 'production',
3941
) {
4042
# "Not-configured" placeholder string. This will be used in places where we
4143
# cannot set an explicit null, and need to supply some kind of value.
@@ -46,6 +48,7 @@
4648
# else.
4749
Node_group {
4850
purge_behavior => none,
51+
environment => $environment,
4952
}
5053

5154
##################################################

plans/convert.pp

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
$exts[peadm::oid('peadm_role')] or String($exts[peadm::oid('pp_role')]) =~ /pe_xl|peadm/
7777
}
7878

79+
# read the pe.conf to figure out the environment for new PE Infra node groups
80+
$node_group_environment = get_node_group_environment($primary_target)
81+
7982
if (!$previously_configured_by_peadm and ($pe_version =~ SemVerRange('< 2019.7.0'))) {
8083
# lint:ignore:strict_indent
8184
fail_plan(@("EOL"/L))
@@ -223,6 +226,7 @@
223226
compiler_pool_address => $compiler_pool_address,
224227
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
225228
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
229+
environment => $node_group_environment,
226230
require => Class['peadm::setup::node_manager_yaml'],
227231
}
228232

0 commit comments

Comments
 (0)