diff --git a/.ruby-version b/.ruby-version
index 6a81b4c83..2451c27ca 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.7.8
+3.0.7
diff --git a/REFERENCE.md b/REFERENCE.md
index ca10ff34e..5d10e5df2 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -29,6 +29,7 @@
* [`peadm::file_or_content`](#peadm--file_or_content)
* [`peadm::flatten_compact`](#peadm--flatten_compact)
* [`peadm::generate_pe_conf`](#peadm--generate_pe_conf): Generate a pe.conf file in JSON format
+* [`peadm::get_node_group_environment`](#peadm--get_node_group_environment): check if a custom PE environment is set in pe.conf
* [`peadm::get_pe_conf`](#peadm--get_pe_conf)
* [`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
* [`peadm::migration_opts_default`](#peadm--migration_opts_default)
@@ -715,6 +716,24 @@ Data type: `Hash`
A hash of settings to set in the config file. Any keys that are set to
undef will not be included in the config file.
+### `peadm::get_node_group_environment`
+
+Type: Puppet Language
+
+check if a custom PE environment is set in pe.conf
+
+#### `peadm::get_node_group_environment(Target $primary)`
+
+The peadm::get_node_group_environment function.
+
+Returns: `Any`
+
+##### `primary`
+
+Data type: `Target`
+
+the FQDN for the primary, here we will read the pe.conf from
+
### `peadm::get_pe_conf`
Type: Puppet Language
diff --git a/functions/get_node_group_environment.pp b/functions/get_node_group_environment.pp
new file mode 100644
index 000000000..e514b4be0
--- /dev/null
+++ b/functions/get_node_group_environment.pp
@@ -0,0 +1,28 @@
+#
+# @summary check if a custom PE environment is set in pe.conf
+#
+# @param primary the FQDN for the primary, here we will read the pe.conf from
+#
+# @see https://www.puppet.com/docs/pe/latest/upgrade_pe#update_environment
+#
+# @author Tim Meusel
+#
+function peadm::get_node_group_environment(Target $primary) {
+ $peconf = peadm::get_pe_conf($primary)
+ # if both are set, they need to be set to the same value
+ # if they are not set, we assume that the user runs their infra in production
+ $pe_install = $peconf['pe_install::install::classification::pe_node_group_environment']
+ $puppet_enterprise = $peconf['puppet_enterprise::master::recover_configuration::pe_environment']
+
+ # check if both are equal
+ # This also evaluates to true if both are undef
+ if $pe_install == $puppet_enterprise {
+ if $pe_install =~ String[1] {
+ return $pe_install
+ } else {
+ return 'production'
+ }
+ } else {
+ 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}")
+ }
+}
diff --git a/manifests/setup/node_manager.pp b/manifests/setup/node_manager.pp
index 65c690440..d2fcdbe44 100644
--- a/manifests/setup/node_manager.pp
+++ b/manifests/setup/node_manager.pp
@@ -23,6 +23,7 @@
# A load balancer address directing traffic to any of the "B" pool
# compilers. This is used for DR configuration in large and extra large
# architectures.
+# @param node_group_environment the environment that will be assigned to all the PE Infra node groups
#
class peadm::setup::node_manager (
String[1] $primary_host,
@@ -36,6 +37,7 @@
Optional[String[1]] $compiler_pool_address = undef,
Optional[String[1]] $internal_compiler_a_pool_address = $server_a_host,
Optional[String[1]] $internal_compiler_b_pool_address = $server_b_host,
+ String[1] $node_group_environment = 'production',
) {
# "Not-configured" placeholder string. This will be used in places where we
# cannot set an explicit null, and need to supply some kind of value.
@@ -46,6 +48,7 @@
# else.
Node_group {
purge_behavior => none,
+ environment => $node_group_environment,
}
##################################################
diff --git a/plans/convert.pp b/plans/convert.pp
index 1995a0b01..525a037cd 100644
--- a/plans/convert.pp
+++ b/plans/convert.pp
@@ -76,6 +76,9 @@
$exts[peadm::oid('peadm_role')] or String($exts[peadm::oid('pp_role')]) =~ /pe_xl|peadm/
}
+ # read the pe.conf to figure out the environment for new PE Infra node groups
+ $node_group_environment = peadm::get_node_group_environment(get_target($primary_target))
+
if (!$previously_configured_by_peadm and ($pe_version =~ SemVerRange('< 2019.7.0'))) {
# lint:ignore:strict_indent
fail_plan(@("EOL"/L))
@@ -223,6 +226,7 @@
compiler_pool_address => $compiler_pool_address,
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
+ node_group_environment => $node_group_environment,
require => Class['peadm::setup::node_manager_yaml'],
}
diff --git a/spec/plans/convert_spec.rb b/spec/plans/convert_spec.rb
index 7140d5982..23c8572f9 100644
--- a/spec/plans/convert_spec.rb
+++ b/spec/plans/convert_spec.rb
@@ -19,7 +19,8 @@
allow_apply
expect_task('peadm::cert_data').return_for_targets('primary' => trustedjson)
- expect_task('peadm::read_file').always_return({ 'content' => '2021.7.8' })
+ expect_task('peadm::read_file').with_params('path' => '/opt/puppetlabs/server/pe_build').always_return({ 'content' => '2021.7.8' })
+ expect_task('peadm::read_file').with_params('path' => '/etc/puppetlabs/enterprise/conf.d/pe.conf').always_return({ 'content' => {} })
# For some reason, expect_plan() was not working??
allow_plan('peadm::modify_certificate').always_return({})