From 17314435a34ac616a4dafadcd6f945b9d66f3985 Mon Sep 17 00:00:00 2001 From: tkishel Date: Wed, 15 Jan 2020 13:13:04 -0800 Subject: [PATCH 1/2] configure classifier data in global hiera.yaml --- plans/action/configure.pp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/plans/action/configure.pp b/plans/action/configure.pp index 5c57f539..4a41d92f 100644 --- a/plans/action/configure.pp +++ b/plans/action/configure.pp @@ -1,11 +1,13 @@ # @summary Configure first-time classification and HA setup # plan peadm::action::configure ( - # Large + # Standard Peadm::SingleTargetSpec $master_host, - Optional[TargetSpec] $compiler_hosts = undef, Optional[Peadm::SingleTargetSpec] $master_replica_host = undef, + # Large + Optional[TargetSpec] $compiler_hosts = undef, + # Extra Large Optional[Peadm::SingleTargetSpec] $puppetdb_database_host = undef, Optional[Peadm::SingleTargetSpec] $puppetdb_database_replica_host = undef, @@ -37,8 +39,29 @@ $compiler_hosts, ) - # Set up the console node groups to configure the various hosts in their - # roles + # Define the global hiera.yaml file on the Master; and syncronize to any Replica and Compilers. + # This enables Data in the Classifier/Console, which is used/required by this architecture. + # Necessary, for example, when promoting the Replica. + $global_hiera_yaml = @("HEREDOC") + --- + version: 5 + hierarchy: + - name: Classifier Configuration Data + data_hash: classifier_data + | HEREDOC + + $global_hiera_yaml_file = "/etc/puppetlabs/puppet/hiera.yaml" + + $hiera_targets = peadm::flatten_compact([ + $master_target, + $master_replica_target, + $compiler_targets, + ]) + + peadm::file_content_upload($global_hiera_yaml, $global_hiera_yaml_file, $hiera_targets) + run_command("chmod 644 ${global_hiera_yaml_file}", $hiera_targets) + + # Set up the console node groups to configure the various hosts in their roles # Pending resolution of Bolt GH-1244, Target objects and their methods are # not accessible inside apply() blocks. Work around the limitation for now From a5d3cad0dfa59bce1892b0369c715c58bc7677bf Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Fri, 17 Jan 2020 10:19:45 -0800 Subject: [PATCH 2/2] Rework algorithm to read hiera.yaml from master So that if the default hiera.yaml changes, the logic will still work, and the source of truth for the contents of hiera.yaml in a deployment managed by peadm is not the peadm module itself. --- plans/action/configure.pp | 30 +++++++++++++----------------- tasks/read_file.json | 10 ++++++++++ tasks/read_file.sh | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 tasks/read_file.json create mode 100755 tasks/read_file.sh diff --git a/plans/action/configure.pp b/plans/action/configure.pp index 4a41d92f..a5679ef1 100644 --- a/plans/action/configure.pp +++ b/plans/action/configure.pp @@ -41,25 +41,21 @@ # Define the global hiera.yaml file on the Master; and syncronize to any Replica and Compilers. # This enables Data in the Classifier/Console, which is used/required by this architecture. - # Necessary, for example, when promoting the Replica. - $global_hiera_yaml = @("HEREDOC") - --- - version: 5 - hierarchy: - - name: Classifier Configuration Data - data_hash: classifier_data - | HEREDOC - - $global_hiera_yaml_file = "/etc/puppetlabs/puppet/hiera.yaml" - - $hiera_targets = peadm::flatten_compact([ - $master_target, + # Necessary, for example, when promoting the Replica due to PE-18400 (and others). + $global_hiera_yaml = run_task('peadm::read_file', $master_target, + path => '/etc/puppetlabs/puppet/hiera.yaml', + ).first['content'] + + run_task('peadm::mkdir_p_file', peadm::flatten_compact([ $master_replica_target, $compiler_targets, - ]) - - peadm::file_content_upload($global_hiera_yaml, $global_hiera_yaml_file, $hiera_targets) - run_command("chmod 644 ${global_hiera_yaml_file}", $hiera_targets) + )], + path => '/etc/puppetlabs/puppet/hiera.yaml', + owner => 'root', + group => 'root', + mode => '0644', + content => $global_hiera_yaml, + ) # Set up the console node groups to configure the various hosts in their roles diff --git a/tasks/read_file.json b/tasks/read_file.json new file mode 100644 index 00000000..974f9288 --- /dev/null +++ b/tasks/read_file.json @@ -0,0 +1,10 @@ +{ + "description": "Read the contents of a file", + "parameters": { + "path": { + "type": "String", + "description": "Path to the file to read" + } + }, + "input_method": "environment" +} diff --git a/tasks/read_file.sh b/tasks/read_file.sh new file mode 100755 index 00000000..fdf60900 --- /dev/null +++ b/tasks/read_file.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +main() { + cat "$PT_path" +} + +outfile=$(mktemp) +main "$@" >"$outfile" 2>&1 +exit_code=$? + +cat <