From b9bfc203624d016de2646df6f999ad5a7004a1d3 Mon Sep 17 00:00:00 2001 From: Ioannis Karasavvaidis Date: Mon, 7 Oct 2024 17:40:47 +0100 Subject: [PATCH 1/2] feat(plans): rename add_compiler plan to add_compilers - Renamed `peadm::add_compiler` plan to `peadm::add_compilers` to support adding multiple compilers. - Updated parameter `compiler_host` to `compiler_hosts` to accept an array of compiler targets. - Modified `dns_alt_names` parameter to accept an array of strings, each representing a comma-separated list of DNS alt names. - Updated all references in documentation and tests to reflect the new plan name. - Enhanced the plan to handle multiple compilers in parallel, including updating PostgreSQL configurations and running necessary tasks on each compiler. BREAKING CHANGE: The plan `peadm::add_compiler` has been renamed to `peadm::add_compilers` and now supports adding multiple compilers simultaneously. --- .../workflows/test-add-compiler-matrix.yml | 4 +- .github/workflows/test-add-compiler.yaml | 4 +- REFERENCE.md | 38 +++---- documentation/add_compiler.md | 64 ----------- documentation/add_compilers.md | 93 ++++++++++++++++ documentation/expanding.md | 58 +++++----- plans/{add_compiler.pp => add_compilers.pp} | 100 +++++++++++------- .../{add_compiler.pp => add_compilers.pp} | 27 +++-- ...compiler_spec.rb => add_compilers_spec.rb} | 16 +-- 9 files changed, 227 insertions(+), 177 deletions(-) delete mode 100644 documentation/add_compiler.md create mode 100644 documentation/add_compilers.md rename plans/{add_compiler.pp => add_compilers.pp} (52%) rename spec/acceptance/peadm_spec/plans/{add_compiler.pp => add_compilers.pp} (82%) rename spec/plans/{add_compiler_spec.rb => add_compilers_spec.rb} (89%) diff --git a/.github/workflows/test-add-compiler-matrix.yml b/.github/workflows/test-add-compiler-matrix.yml index a7575af0..b3009ed7 100644 --- a/.github/workflows/test-add-compiler-matrix.yml +++ b/.github/workflows/test-add-compiler-matrix.yml @@ -84,10 +84,10 @@ jobs: architecture=${{ matrix.architecture }} \ console_password=${{ secrets.CONSOLE_PASSWORD }} \ version=${{ matrix.version }} - - name: Run add_compiler plan + - name: Run add_compilers plan timeout-minutes: 50 run: | - bundle exec bolt plan run peadm_spec::add_compiler -v \ + bundle exec bolt plan run peadm_spec::add_compilers -v \ --inventoryfile spec/fixtures/litmus_inventory.yaml \ --modulepath spec/fixtures/modules \ architecture=${{ matrix.architecture }} diff --git a/.github/workflows/test-add-compiler.yaml b/.github/workflows/test-add-compiler.yaml index e88a1c6e..52711f87 100644 --- a/.github/workflows/test-add-compiler.yaml +++ b/.github/workflows/test-add-compiler.yaml @@ -85,10 +85,10 @@ jobs: architecture=${{ matrix.architecture }} \ version=${{ matrix.version }} \ console_password=${{ secrets.CONSOLE_PASSWORD } - - name: Run add_compiler plan + - name: Run add_compilers plan timeout-minutes: 50 run: | - bundle exec bolt plan run peadm_spec::add_compiler -v \ + bundle exec bolt plan run peadm_spec::add_compilers -v \ --inventoryfile spec/fixtures/litmus_inventory.yaml \ --modulepath spec/fixtures/modules \ architecture=${{ matrix.architecture }} \ diff --git a/REFERENCE.md b/REFERENCE.md index 7aef694b..4275c69f 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -92,7 +92,7 @@ #### Public Plans -* [`peadm::add_compiler`](#peadm--add_compiler): Add a new compiler to a PE architecture or replace an existing one with new configuration. +* [`peadm::add_compilers`](#peadm--add_compilers): Add new compilers to a PE architecture or replace an existing with new configuration. * [`peadm::add_database`](#peadm--add_database) * [`peadm::add_replica`](#peadm--add_replica): Add or replace a replica host. Supported use cases: @@ -1594,49 +1594,49 @@ Which port to query the status API on ## Plans -### `peadm::add_compiler` +### `peadm::add_compilers` -Add a new compiler to a PE architecture or replace an existing one with new configuration. +Add new compilers to a PE architecture or replace an existing with new configuration. #### Parameters -The following parameters are available in the `peadm::add_compiler` plan: +The following parameters are available in the `peadm::add_compilers` plan: -* [`avail_group_letter`](#-peadm--add_compiler--avail_group_letter) -* [`compiler_host`](#-peadm--add_compiler--compiler_host) -* [`dns_alt_names`](#-peadm--add_compiler--dns_alt_names) -* [`primary_host`](#-peadm--add_compiler--primary_host) -* [`primary_postgresql_host`](#-peadm--add_compiler--primary_postgresql_host) +* [`avail_group_letter`](#-peadm--add_compilers--avail_group_letter) +* [`compiler_hosts`](#-peadm--add_compilers--compiler_hosts) +* [`dns_alt_names`](#-peadm--add_compilers--dns_alt_names) +* [`primary_host`](#-peadm--add_compilers--primary_host) +* [`primary_postgresql_host`](#-peadm--add_compilers--primary_postgresql_host) -##### `avail_group_letter` +##### `avail_group_letter` Data type: `Enum['A', 'B']` -_ Either A or B; whichever of the two letter designations the compiler is being assigned to +_ Either A or B; whichever of the two letter designations the compilers are being assigned to Default value: `'A'` -##### `compiler_host` +##### `compiler_hosts` -Data type: `Peadm::SingleTargetSpec` +Data type: `TargetSpec` -_ The hostname and certname of the new compiler +_ The hostnames and certnames of the new compilers -##### `dns_alt_names` +##### `dns_alt_names` -Data type: `Optional[String[1]]` +Data type: `Optional[Array[String[1]]]` -_ A comma_separated list of DNS alt names for the compiler +_ An array of strings, where each string is a comma-separated list of DNS alt names for the compilers. Order matters; if a compiler doesn't need dns_alt_names, use "undef" as string. Default value: `undef` -##### `primary_host` +##### `primary_host` Data type: `Peadm::SingleTargetSpec` _ The hostname and certname of the primary Puppet server -##### `primary_postgresql_host` +##### `primary_postgresql_host` Data type: `Optional[Peadm::SingleTargetSpec]` diff --git a/documentation/add_compiler.md b/documentation/add_compiler.md deleted file mode 100644 index 737304e4..00000000 --- a/documentation/add_compiler.md +++ /dev/null @@ -1,64 +0,0 @@ -# Add Compiler - -- [Add Compiler](#Add-Compiler) - - [Introduction](#Introduction) - - [Add a compiler to an existing PE cluster](#Add-a-compiler-to-an-existing-PE-cluster) - - [Running the `add_compiler` plan](#running-the-add_compiler-plan) - - [Optional Parameters](#optional-parameters) - - -## Introduction - -The `peadm::add_compiler` plan can be used to add a new compiler to a PE cluster or replace an existing one with new configuration. - - -## Add a compiler to an existing PE cluster - -As seen in the example below, this is the minimal parameters required to add a compiler to an existing PE cluster. These can be passed as command line variables to the plan, or in this case added to a params.json file. - -```json -{ - "compiler_host": "pe-xl-compiler-0.lab1.puppet.vm", - "primary_host": "pe-xl-core-0.lab1.puppet.vm" -} -``` - -## Running the `add_compiler` plan -``` -bolt plan run peadm::add_compiler --params @params.json -``` - -This command will retrieve the current PEADM configuration to determine the setup rules needed for a compiler's secondary PuppetDB instances. The plan will configure the primary with appropriate rules for allowing access from the new compiler. On the primary, the `puppet` service is stopped and the `pe-postgresql` service is reloaded. If required, a puppet agent will be installed on the new compiler host. The compiler agent's certificate is regenerated to include data required by the `peadm::subplans::component_install` plan. A subsequent Puppet agent run will happen on the following components. -* _\_ -* _\_ -* _\_ -* _\_ - - The `puppet` service is then restarted. - - -## Optional Parameters - -As well as `compiler_host` and `primary_host`, the `add_compiler` plan has a number of optional parameters. These can be viewed in the following params example. - -```json -{ - "avail_group_letter": "B", - "compiler_host": "pe-xl-compiler-0.lab1.puppet.vm", - "dns_alt_names": [ "puppet", "puppet.lab1.puppet.vm" ], - "primary_host": "pe-xl-core-0.lab1.puppet.vm", - "primary_postgresql_host": "pe-psql-6251cd-0.us-west1-a.c.slice-cody.internal" -} -``` - -Please note, the optional parameters and values of the plan are as follows. - - -| Parameter | Default value | Description | -|--------------------------|---------------|--------------------------------------------------| -| `avail_group_letter` | `A` | By default, each compiler will be added to the primary group A. | -| `dns_alt_names` | `undef` | | -| `primary_postgresql_host`| `undef` | By default, this will pre-populate to the required value depending if your architecture contains HA and or external databases. | - -For more information around adding compilers to your infrastructure [Expanding Your Deployment](expanding.md#adding-compilers-with-peadmadd_compiler) - diff --git a/documentation/add_compilers.md b/documentation/add_compilers.md new file mode 100644 index 00000000..9b206519 --- /dev/null +++ b/documentation/add_compilers.md @@ -0,0 +1,93 @@ +# Add Compilers + +- [Add Compilers](#Add-Compilers) + - [Introduction](#Introduction) + - [Add compilers to an existing PE cluster](#Add-compilers-to-an-existing-PE-cluster) + - [Running the `add_compilers` plan](#running-the-add_compilers-plan) + - [Optional Parameters](#optional-parameters) + +## Introduction + +The `peadm::add_compilers` plan can be used to add new compilers to a PE cluster or replace an existing with new configuration. + +## Add compilers to an existing PE cluster + +As seen in the example below, this is the minimal parameters required to add a compiler to an existing PE cluster. These can be passed as command line variables to the plan, or in this case added to a params.json file. + +```json +{ + "compiler_hosts": "pe-xl-compiler-0.lab1.puppet.vm", + "primary_host": "pe-xl-core-0.lab1.puppet.vm" +} +``` + +And for multiple compilers, this is the minimal parameters required. + +```json +{ + "compiler_hosts": [ + "pe-xl-compiler-0.lab1.puppet.vm", + "pe-xl-compiler-1.lab1.puppet.vm" + ], + "primary_host": "pe-xl-core-0.lab1.puppet.vm" +} +``` + +## Running the `add_compiler` plan + +``` +bolt plan run peadm::add_compilers --params @params.json +``` + +This command will retrieve the current PEADM configuration to determine the setup rules needed for a compiler's secondary PuppetDB instances. The plan will configure the primary with appropriate rules for allowing access from the new compiler. On the primary, the `puppet` service is stopped and the `pe-postgresql` service is reloaded. If required, a puppet agent will be installed on the new compiler host. The compiler agent's certificate is regenerated to include data required by the `peadm::subplans::component_install` plan. A subsequent Puppet agent run will happen on the following components. + +- _\_ +- _\_ +- _\_ +- _\_ + +The `puppet` service is then restarted. + +## Optional Parameters + +As well as `compiler_hosts` and `primary_host`, the `add_compiler` plan has a number of optional parameters. These can be viewed in the following params example. + +```json +{ + "avail_group_letter": "B", + "compiler_hosts": "pe-xl-compiler-0.lab1.puppet.vm", + "dns_alt_names": ["puppet,puppet.lab1.puppet.vm"], + "primary_host": "pe-xl-core-0.lab1.puppet.vm", + "primary_postgresql_host": "pe-psql-6251cd-0.us-west1-a.c.slice-cody.internal" +} +``` + +for multiple compilers. + +```json +{ + "avail_group_letter": "B", + "compiler_hosts": [ + "pe-xl-compiler-0.lab1.puppet.vm", + "pe-xl-compiler-1.lab1.puppet.vm" + ], + "dns_alt_names": [ + "puppet,puppet.lab1.puppet.vm", + "puppet2,puppet.lab2.puppet.vm" + ], + "primary_host": "pe-xl-core-0.lab1.puppet.vm", + "primary_postgresql_host": "pe-psql-6251cd-0.us-west1-a.c.slice-cody.internal" +} +``` + +Please note, the optional parameters and values of the plan are as follows. + + + +| Parameter | Default value | Description | +| ------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `avail_group_letter` | `A` | By default, each compiler will be added to the primary group A. | +| `dns_alt_names` | `undef` | | +| `primary_postgresql_host` | `undef` | By default, this will pre-populate to the required value depending if your architecture contains HA and or external databases. | + +For more information around adding compilers to your infrastructure [Expanding Your Deployment](expanding.md#adding-compilers-with-peadmadd_compiler) diff --git a/documentation/expanding.md b/documentation/expanding.md index 875e417d..bee8b7fe 100644 --- a/documentation/expanding.md +++ b/documentation/expanding.md @@ -2,29 +2,29 @@ Documentation which provides instructions for expanding existing PEADM based deployments of Puppet Enterprise with compilers, disaster recovery replicas, and external databases. -* [Adding External Databases with peadm::add_database](#adding-external-databases-with-peadmadd_database) -* [Enable Disaster Recovery and Add a Replica with peadm::add_replica](#enable-disaster-recovery-and-add-a-replica-with-peadmadd_replica) -* [Adding Compilers with peadm::add_compiler](#adding-compilers-with-peadmadd_compiler) +- [Adding External Databases with peadm::add_database](#adding-external-databases-with-peadmadd_database) +- [Enable Disaster Recovery and Add a Replica with peadm::add_replica](#enable-disaster-recovery-and-add-a-replica-with-peadmadd_replica) +- [Adding Compilers with peadm::add_compilers](#adding-compilers-with-peadmadd_compilers) ### Notes -* CLI options for `add_replica`, `add_compiler`, and `add_database` are unfortunately inconsistent - * This is the result of a history of organic development -* There is an inconsistency in the output of the task `peadm::get_peadm_config` and the naming of related parameters - * The documentation and CLI refer to availability groups but the output from the task will refer to associated data as role letters -* The term host and server are interchangeable throughout the documentation - * When ever possible documentation will prefer the term server but plan parameters and `peadm::get_peadm_config` often uses the term host +- CLI options for `add_replica`, `add_compilers`, and `add_database` are unfortunately inconsistent + - This is the result of a history of organic development +- There is an inconsistency in the output of the task `peadm::get_peadm_config` and the naming of related parameters + - The documentation and CLI refer to availability groups but the output from the task will refer to associated data as role letters +- The term host and server are interchangeable throughout the documentation + - When ever possible documentation will prefer the term server but plan parameters and `peadm::get_peadm_config` often uses the term host ### Key -* _\_ - The FQDN and certname of the Primary Puppet server -* _\_ - The FQDN and certname of the new PE-PostgreSQL server to initialize -* _\_ - The FQDN and certname of the new Replica Puppet server to initialize -* _\_ - The FQDN and certname of the Replica PE-PostgreSQL server -* _\_ - The FQDN and certname of the new Compiler to initialize -* _\_ - The target availability group letter to assign to the new Compiler -* _\_ - The FQDN and certname of the Primary Puppet server that is assigned to the new Compiler's target availability group letter -* _\_ - The FQDN and certname of the PE-PostgreSQL server that is assigned to the new Compiler's target availability group letter +- _\_ - The FQDN and certname of the Primary Puppet server +- _\_ - The FQDN and certname of the new PE-PostgreSQL server to initialize +- _\_ - The FQDN and certname of the new Replica Puppet server to initialize +- _\_ - The FQDN and certname of the Replica PE-PostgreSQL server +- _\_ - The FQDN and certname of the new Compiler to initialize +- _\_ - The target availability group letter to assign to the new Compiler +- _\_ - The FQDN and certname of the Primary Puppet server that is assigned to the new Compiler's target availability group letter +- _\_ - The FQDN and certname of the PE-PostgreSQL server that is assigned to the new Compiler's target availability group letter ## Adding External Databases with peadm::add_database @@ -50,7 +50,7 @@ The initial Primary will be assigned availability group **A** and the initial Re In deployments which adopted the Extra Large deployment architecture you must provide the `replica_postgresql_host` parameter set to the PE-PostgreSQL server which will be collocated within the same availability group as the new Replica Puppet server. The `peadm::get_peadm_config` task will help you determine the most appropriate value. In the **Example** section below, the task has figured out which PE-PostgreSQL server is the Replica PE-PostgreSQL database server. You'll find the value at `params.replica_postgresql_host`, which is equal to `pe-psql-6251cd-1.us-west1-b.c.slice-cody.internal`. Reminder, the Replica PE-PostgreSQL server **MUST** be provisioned and deployed prior to initializing a Replica Puppet server. - bolt task run peadm::get_peadm_config --targets + bolt task run peadm::get_peadm_config --targets bolt plan run peadm::add_replica primary_host= replica_host= replica_postgresql_host= **Example** @@ -87,7 +87,7 @@ In deployments which adopted the Extra Large deployment architecture you must pr "pe-compiler-6251cd-1.us-west1-b.c.slice-cody.internal" ], "B": [ - + ] } } @@ -95,21 +95,21 @@ In deployments which adopted the Extra Large deployment architecture you must pr Successful on 1 target: pe-server-6251cd-0.us-west1-a.c.slice-cody.internal Ran on 1 target in 2.56 sec -## Adding Compilers with peadm::add_compiler +## Adding Compilers with peadm::add_compilers -The Standard deployment architecture is the only deployment architecture of the three which does not include Compilers, the lack of them is what differentiates the Standard from Large deployment architecture. Deployment architecture has no effect on the process for adding Compilers to a deployment. The [peadm::add_compiler](https://github.com/puppetlabs/puppetlabs-peadm/blob/main/plans/add_compiler.pp) plan functions identical in all three deployment architectures, whether you are adding the 1st or the 100th but some options do change slightly depending. +The Standard deployment architecture is the only deployment architecture of the three which does not include Compilers, the lack of them is what differentiates the Standard from Large deployment architecture. Deployment architecture has no effect on the process for adding Compilers to a deployment. The [peadm::add_compilers](https://github.com/puppetlabs/puppetlabs-peadm/blob/main/plans/add_compilers.pp) plan functions identical in all three deployment architectures, whether you are adding the 1st or the 100th but some options do change slightly depending. ### Adding Compilers to Standard and Large without disaster recovery -The command invocation is identical when adding Compilers to a Standard or Large deployment architecture if disaster recovery (DR) is not enabled and a replica Puppet server has not been provisioned. Take note that `avail_group_letter` is not required in this **no DR** scenario. By default, the value of this parameter is set to **A**. +The command invocation is identical when adding Compilers to a Standard or Large deployment architecture if disaster recovery (DR) is not enabled and a replica Puppet server has not been provisioned. Take note that `avail_group_letter` is not required in this **no DR** scenario. By default, the value of this parameter is set to **A**. - bolt plan run peadm::add_compiler primary_host= compiler_host= + bolt plan run peadm::add_compilers primary_host= compiler_hosts= ### Adding Compilers to Extra Large without disaster recovery When adding a compiler to a deployment which has adopted the Extra Large deployment architecture in a **no DR** scenario, the only difference is that the `primary_postgresql_host` changes to the value of the primary PE-PostgreSQL server as opposed to the Primary Puppet server. - bolt plan run peadm::add_compiler primary_host= compiler_host= + bolt plan run peadm::add_compilers primary_host= compiler_hosts= ### Adding Compilers to Standard and Large when disaster recovery has been enabled @@ -117,12 +117,12 @@ As was described in the section documenting [peadm::add_replica](#enable-disaste The name of the `primary_postgresql_host` parameter can be confusing, it is **NOT** always equal to the Primary Puppet server or Primary PE-PostgreSQL server, it can also be equal to the replica Puppet server or replica PE-PostgreSQL server. It should be set to the server which is a member of the compiler's target availability group. In most cases this will be handled behind the scenes and not be required to be worked out by the user. The easiest way to determine this value is to first run the `peadm::get_peadm_config` task and source the value from its output. In the **Example** section the value to use when targeting the **B** group is `pe-server-59ab63-1.us-west1-b.c.slice-cody.internal`. You'll find the value at `role-letter.server.B`. - bolt plan run peadm::get_peadm_config --targets - bolt plan run peadm::add_compiler primary_host= compiler_host= avail_group_letter= primary_postgresql_host= + bolt plan run peadm::get_peadm_config --targets + bolt plan run peadm::add_compilers primary_host= compiler_hosts= avail_group_letter= primary_postgresql_host= **Example** - % bolt task run peadm::get_peadm_config --targets pe-server-59ab63-0.us-west1-a.c.slice-cody.internal + % bolt task run peadm::get_peadm_config --targets pe-server-59ab63-0.us-west1-a.c.slice-cody.internal Started on pe-server-59ab63-0.us-west1-a.c.slice-cody.internal... Finished on pe-server-59ab63-0.us-west1-a.c.slice-cody.internal: { @@ -165,8 +165,8 @@ The name of the `primary_postgresql_host` parameter can be confusing, it is **NO Adding a Compiler to a deployment which has adopted the Extra Large deployment architecture with disaster recovery (DR) enabled is similar to Standard and Large but the value of `primary_postgresql_host` will no longer correspond to the Primary or Replica Puppet server since PuppetDB databases are now hosted externally. In the **Example** section, the value to use when targeting the **A** group is `pe-psql-65e03f-0.us-west1-a.c.slice-cody.internal`. You'll find the value at `role-letter.postgresql.A`. - bolt plan run peadm::get_peadm_config --targets - bolt plan run peadm::add_compiler primary_host= compiler_host= avail_group_letter= primary_postgresql_host= + bolt plan run peadm::get_peadm_config --targets + bolt plan run peadm::add_compilers primary_host= compiler_hosts= avail_group_letter= primary_postgresql_host= **Example** diff --git a/plans/add_compiler.pp b/plans/add_compilers.pp similarity index 52% rename from plans/add_compiler.pp rename to plans/add_compilers.pp index ba09e826..879d9fb2 100644 --- a/plans/add_compiler.pp +++ b/plans/add_compilers.pp @@ -1,19 +1,19 @@ # @api public # -# @summary Add a new compiler to a PE architecture or replace an existing one with new configuration. -# @param avail_group_letter _ Either A or B; whichever of the two letter designations the compiler is being assigned to -# @param compiler_host _ The hostname and certname of the new compiler -# @param dns_alt_names _ A comma_separated list of DNS alt names for the compiler +# @summary Add new compilers to a PE architecture or replace an existing with new configuration. +# @param avail_group_letter _ Either A or B; whichever of the two letter designations the compilers are being assigned to +# @param compiler_hosts _ The hostnames and certnames of the new compilers +# @param dns_alt_names _ An array of strings, where each string is a comma-separated list of DNS alt names for the compilers. Order matters; if a compiler doesn't need dns_alt_names, use "undef" as string. # @param primary_host _ The hostname and certname of the primary Puppet server # @param primary_postgresql_host _ The hostname and certname of the PE-PostgreSQL server with availability group $avail_group_letter -plan peadm::add_compiler( +plan peadm::add_compilers( Enum['A', 'B'] $avail_group_letter = 'A' , - Optional[String[1]] $dns_alt_names = undef, - Peadm::SingleTargetSpec $compiler_host, + Optional[Array[String[1]]] $dns_alt_names = undef, + TargetSpec $compiler_hosts, Peadm::SingleTargetSpec $primary_host, Optional[Peadm::SingleTargetSpec] $primary_postgresql_host = undef, ) { - $compiler_target = peadm::get_targets($compiler_host, 1) + $compiler_targets = peadm::get_targets($compiler_hosts) $primary_target = peadm::get_targets($primary_host, 1) # Get current peadm config to determine where to setup additional rules for @@ -57,9 +57,11 @@ ])) apply($replica_puppetdb_target) { - file_line { 'pe-puppetdb-compiler-cert-allow': - path => '/etc/puppetlabs/puppetdb/certificate-allowlist', - line => $compiler_target.peadm::certname(), + $compiler_targets.each |$compiler_target| { + file_line { "pe-puppetdb-compiler-cert-allow-${compiler_target.peadm::certname()}": + path => '/etc/puppetlabs/puppetdb/certificate-allowlist', + line => $compiler_target.peadm::certname(), + } } } @@ -72,39 +74,58 @@ # pe-puppetdb-pe-puppetdb-migrator-map pe-puppetdb-migrator apply($primary_postgresql_target) { - file_line { 'pe-puppetdb-pe-puppetdb-map': - path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf", - line => "pe-puppetdb-pe-puppetdb-map ${compiler_target.peadm::certname()} pe-puppetdb", - } - file_line { 'pe-puppetdb-pe-puppetdb-migrator-map': - path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf", - line => "pe-puppetdb-pe-puppetdb-migrator-map ${compiler_target.peadm::certname()} pe-puppetdb-migrator", - } - file_line { 'pe-puppetdb-pe-puppetdb-read-map': - path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf", - line => "pe-puppetdb-pe-puppetdb-read-map ${compiler_target.peadm::certname()} pe-puppetdb-read", + $compiler_targets.each |$compiler_target| { + file_line { "pe-puppetdb-pe-puppetdb-map-${compiler_target.peadm::certname()}": + path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf", + line => "pe-puppetdb-pe-puppetdb-map ${compiler_target.peadm::certname()} pe-puppetdb", + } + file_line { "pe-puppetdb-pe-puppetdb-migrator-map-${compiler_target.peadm::certname()}": + path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf", + line => "pe-puppetdb-pe-puppetdb-migrator-map ${compiler_target.peadm::certname()} pe-puppetdb-migrator", + } + file_line { "pe-puppetdb-pe-puppetdb-read-map-${compiler_target.peadm::certname()}": + path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf", + line => "pe-puppetdb-pe-puppetdb-read-map ${compiler_target.peadm::certname()} pe-puppetdb-read", + } } } # Reload pe-postgresql.service run_command('systemctl reload pe-postgresql.service', $primary_postgresql_target) + $compiler_targets_with_dns_alt_names = $compiler_targets.map |$index, $compiler_target| { + $current_dns_alt_names = $dns_alt_names ? { + undef => undef, + default => $dns_alt_names[$index] ? { + 'undef' => undef, + default => $dns_alt_names[$index], + } + } + + [$current_dns_alt_names, $compiler_target] + } + # Install agent (if required) and regenerate agent certificate to add required data with peadm::subplans::component_install - run_plan('peadm::subplans::component_install', $compiler_target, - primary_host => $primary_target, - avail_group_letter => $avail_group_letter, - dns_alt_names => $dns_alt_names, - role => 'pe_compiler', - ) - - # Source the global hiera.yaml from Primary and synchronize to new compiler - run_plan('peadm::util::copy_file', $compiler_target, - source_host => $primary_target, - path => '/etc/puppetlabs/puppet/hiera.yaml' - ) - - # On , run puppet agent - run_task('peadm::puppet_runonce', $compiler_target) + parallelize($compiler_targets_with_dns_alt_names) |$pair| { + $current_dns_alt_names = $pair[0] + $compiler_target = $pair[1] + + run_plan('peadm::subplans::component_install', $compiler_target, + primary_host => $primary_target, + avail_group_letter => $avail_group_letter, + dns_alt_names => $current_dns_alt_names, + role => 'pe_compiler', + ) + + # Source the global hiera.yaml from Primary and synchronize to new compiler + run_plan('peadm::util::copy_file', $compiler_target, + source_host => $primary_target, + path => '/etc/puppetlabs/puppet/hiera.yaml' + ) + + # On , run puppet agent + run_task('peadm::puppet_runonce', $compiler_target) + } # On , run puppet agent run_task('peadm::puppet_runonce', $primary_postgresql_target) @@ -116,8 +137,9 @@ run_command('systemctl start puppet.service', peadm::flatten_compact([ $primary_postgresql_target, $replica_puppetdb_target, - $compiler_target, + $compiler_targets, ])) - return("Adding or replacing compiler ${$compiler_target.peadm::certname()} succeeded.") + $compiler_names = $compiler_targets.map |$compiler_target| { $compiler_target.peadm::certname() }.join(', ') + return("Adding or replacing compiler(s) ${compiler_names} succeeded.") } diff --git a/spec/acceptance/peadm_spec/plans/add_compiler.pp b/spec/acceptance/peadm_spec/plans/add_compilers.pp similarity index 82% rename from spec/acceptance/peadm_spec/plans/add_compiler.pp rename to spec/acceptance/peadm_spec/plans/add_compilers.pp index a78a3dca..3b7485ce 100644 --- a/spec/acceptance/peadm_spec/plans/add_compiler.pp +++ b/spec/acceptance/peadm_spec/plans/add_compilers.pp @@ -1,7 +1,6 @@ -plan peadm_spec::add_compiler ( +plan peadm_spec::add_compilers ( String[1] $architecture, ) { - $t = get_targets('*') wait_until_available($t) @@ -22,29 +21,29 @@ $arch_params = case $architecture { - 'standard': {{ + 'standard': {{ primary_host => $primary_host, primary_postgresql_host => $primary_host, - compiler_host => $compiler_host, - }} - 'large': {{ + compiler_hosts => $compiler_host, + } } + 'large': {{ primary_host => $primary_host, primary_postgresql_host => $primary_host, - compiler_host => $compiler_host, - }} - 'extra-large': {{ + compiler_hosts => $compiler_host, + } } + 'extra-large': {{ primary_host => $primary_host, primary_postgresql_host => $t.filter |$n| { $n.vars['role'] == 'primary-pdb-postgresql' }, - compiler_host => $compiler_host, - }} - default: { fail('Invalid architecture!') } - } + compiler_hosts => $compiler_host, + } } + default: { fail('Invalid architecture!') } + } $compiler_count_query = 'inventory[count()] { trusted.extensions.pp_auth_role = "pe_compiler"}' $query_result = run_command("/opt/puppetlabs/bin/puppet query \'${compiler_count_query}\'", $primary_host).first['stdout'] $first_count = parsejson($query_result)[0]['count'] - $result = run_plan('peadm::add_compiler', $arch_params + $common_params) + $result = run_plan('peadm::add_compilers', $arch_params + $common_params) $query_result2 = run_command("/opt/puppetlabs/bin/puppet query \'${compiler_count_query}\'", $primary_host).first['stdout'] $second_count = parsejson($query_result2)[0]['count'] diff --git a/spec/plans/add_compiler_spec.rb b/spec/plans/add_compilers_spec.rb similarity index 89% rename from spec/plans/add_compiler_spec.rb rename to spec/plans/add_compilers_spec.rb index cd493328..9dbb4f94 100644 --- a/spec/plans/add_compiler_spec.rb +++ b/spec/plans/add_compilers_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'peadm::add_compiler' do +describe 'peadm::add_compilers' do include BoltSpec::Plans def allow_standard_non_returning_calls @@ -14,7 +14,7 @@ def allow_standard_non_returning_calls let(:params) do { 'primary_host' => 'primary', - 'compiler_host' => 'compiler', + 'compiler_hosts' => 'compiler', } end @@ -57,7 +57,7 @@ def allow_standard_non_returning_calls expect_plan('peadm::util::copy_file').be_called_times(1) expect_task('peadm::puppet_runonce').with_targets(['compiler']) expect_task('peadm::puppet_runonce').with_targets(['server_a']) - expect(run_plan('peadm::add_compiler', params)).to be_ok + expect(run_plan('peadm::add_compilers', params)).to be_ok end it 'handles different avail_group_letter values' do @@ -72,7 +72,7 @@ def allow_standard_non_returning_calls expect_task('peadm::puppet_runonce').with_targets(['compiler']) expect_task('peadm::puppet_runonce').with_targets(['server_a']) expect_task('peadm::puppet_runonce').with_targets(['server_b']) - expect(run_plan('peadm::add_compiler', params_with_avail_group_b)).to be_ok + expect(run_plan('peadm::add_compilers', params_with_avail_group_b)).to be_ok end it 'handles specified primary_postgresql_host' do @@ -85,7 +85,7 @@ def allow_standard_non_returning_calls expect_plan('peadm::util::copy_file').be_called_times(1) expect_task('peadm::puppet_runonce').with_targets(['compiler']) expect_task('peadm::puppet_runonce').with_targets(['custom_postgresql']) - expect(run_plan('peadm::add_compiler', params_with_primary_postgresql_host)).to be_ok + expect(run_plan('peadm::add_compilers', params_with_primary_postgresql_host)).to be_ok end it 'handles external postgresql host group A' do @@ -100,7 +100,7 @@ def allow_standard_non_returning_calls expect_plan('peadm::util::copy_file').be_called_times(1) expect_task('peadm::puppet_runonce').with_targets(['compiler']) expect_task('peadm::puppet_runonce').with_targets(['external_postgresql']) - expect(run_plan('peadm::add_compiler', params)).to be_ok + expect(run_plan('peadm::add_compilers', params)).to be_ok end it 'handles external postgresql host group A with replica' do @@ -116,7 +116,7 @@ def allow_standard_non_returning_calls expect_task('peadm::puppet_runonce').with_targets(['compiler']) expect_task('peadm::puppet_runonce').with_targets(['external_postgresql']) expect_task('peadm::puppet_runonce').with_targets(['replica']) - expect(run_plan('peadm::add_compiler', params)).to be_ok + expect(run_plan('peadm::add_compilers', params)).to be_ok end it 'handles external postgresql host group B' do @@ -131,7 +131,7 @@ def allow_standard_non_returning_calls expect_task('peadm::puppet_runonce').with_targets(['compiler']) expect_task('peadm::puppet_runonce').with_targets(['replica_external_postgresql']) expect_task('peadm::puppet_runonce').with_targets(['server_a']) - expect(run_plan('peadm::add_compiler', params_with_avail_group_b)).to be_ok + expect(run_plan('peadm::add_compilers', params_with_avail_group_b)).to be_ok end end end From ff3806960af20ef717a20cf5deca9bf1bf1fec05 Mon Sep 17 00:00:00 2001 From: Ioannis Karasavvaidis Date: Wed, 9 Oct 2024 17:36:09 +0100 Subject: [PATCH 2/2] feat(plans): add peadm::add_compiler plan - Introduced a new plan `peadm::add_compiler` as a proxy for `peadm::add_compilers`. - Added documentation for the new plan in REFERENCE.md. - Parameters include `avail_group_letter`, `compiler_host`, `dns_alt_names`, `primary_host`, and `primary_postgresql_host`. - The plan outputs a deprecation message and calls `peadm::add_compilers` with the provided parameters. --- REFERENCE.md | 51 +++++++++++++++++++++++++++++++++++++++++++ plans/add_compiler.pp | 24 ++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 plans/add_compiler.pp diff --git a/REFERENCE.md b/REFERENCE.md index 4275c69f..5b8e8295 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -92,6 +92,7 @@ #### Public Plans +* [`peadm::add_compiler`](#peadm--add_compiler): Proxy plan for peadm::add_compilers. * [`peadm::add_compilers`](#peadm--add_compilers): Add new compilers to a PE architecture or replace an existing with new configuration. * [`peadm::add_database`](#peadm--add_database) * [`peadm::add_replica`](#peadm--add_replica): Add or replace a replica host. @@ -1594,6 +1595,56 @@ Which port to query the status API on ## Plans +### `peadm::add_compiler` + +Proxy plan for peadm::add_compilers. + +#### Parameters + +The following parameters are available in the `peadm::add_compiler` plan: + +* [`avail_group_letter`](#-peadm--add_compiler--avail_group_letter) +* [`compiler_host`](#-peadm--add_compiler--compiler_host) +* [`dns_alt_names`](#-peadm--add_compiler--dns_alt_names) +* [`primary_host`](#-peadm--add_compiler--primary_host) +* [`primary_postgresql_host`](#-peadm--add_compiler--primary_postgresql_host) + +##### `avail_group_letter` + +Data type: `Enum['A', 'B']` + +_ Either A or B; whichever of the two letter designations the compiler are being assigned to + +Default value: `'A'` + +##### `compiler_host` + +Data type: `Peadm::SingleTargetSpec` + +_ The hostname and certname of the new compiler + +##### `dns_alt_names` + +Data type: `Optional[String[1]]` + +_ A comma-separated list of DNS alt names for the compiler. + +Default value: `undef` + +##### `primary_host` + +Data type: `Peadm::SingleTargetSpec` + +_ The hostname and certname of the primary Puppet server + +##### `primary_postgresql_host` + +Data type: `Optional[Peadm::SingleTargetSpec]` + +_ The hostname and certname of the PE-PostgreSQL server with availability group $avail_group_letter + +Default value: `undef` + ### `peadm::add_compilers` Add new compilers to a PE architecture or replace an existing with new configuration. diff --git a/plans/add_compiler.pp b/plans/add_compiler.pp new file mode 100644 index 00000000..15ce426a --- /dev/null +++ b/plans/add_compiler.pp @@ -0,0 +1,24 @@ +# @api public +# +# @summary Proxy plan for peadm::add_compilers. +# @param avail_group_letter _ Either A or B; whichever of the two letter designations the compiler are being assigned to +# @param compiler_host _ The hostname and certname of the new compiler +# @param dns_alt_names _ A comma-separated list of DNS alt names for the compiler. +# @param primary_host _ The hostname and certname of the primary Puppet server +# @param primary_postgresql_host _ The hostname and certname of the PE-PostgreSQL server with availability group $avail_group_letter +plan peadm::add_compiler( + Enum['A', 'B'] $avail_group_letter = 'A' , + Optional[String[1]] $dns_alt_names = undef, + Peadm::SingleTargetSpec $compiler_host, + Peadm::SingleTargetSpec $primary_host, + Optional[Peadm::SingleTargetSpec] $primary_postgresql_host = undef, +) { + out::message('Warning: The add_compiler plan is deprecated and will be removed in a future release. Please use the add_compilers plan instead. ') + run_plan('peadm::add_compilers', + avail_group_letter => $avail_group_letter, + dns_alt_names => $dns_alt_names ? { undef => undef, default => Array($dns_alt_names) }, + compiler_hosts => $compiler_host, + primary_host => $primary_host, + primary_postgresql_host => $primary_postgresql_host, + ) +}