From 4eb14cc1d6ac9822dbcdac940be8d826d803d862 Mon Sep 17 00:00:00 2001 From: tkishel Date: Thu, 17 Oct 2019 11:24:02 -0700 Subject: [PATCH] (maint) define an intuitive output order --- lib/puppet_x/puppetlabs/tune.rb | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/puppet_x/puppetlabs/tune.rb b/lib/puppet_x/puppetlabs/tune.rb index 5dc8d38..b817097 100755 --- a/lib/puppet_x/puppetlabs/tune.rb +++ b/lib/puppet_x/puppetlabs/tune.rb @@ -137,7 +137,7 @@ def output_infrastructure def output_current_settings current_total_puppetserver_jrubies = collect_current_settings - @current_collected_nodes.each do |certname, node| + @current_collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, node| next if @options[:node] && certname != @options[:node] output_current_settings_for_node(certname, node) end @@ -151,7 +151,7 @@ def output_optimized_settings optimized_total_puppetserver_jrubies = collect_optimized_settings collect_optimized_settings_common_to_all_nodes - @collected_nodes.each do |certname, node| + @collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, node| next if @options[:node] && certname != @options[:node] output_optimized_settings_for_node(certname, node) end @@ -169,7 +169,7 @@ def output_compare_current_and_optimized_settings collect_current_settings collect_optimized_settings - @current_collected_nodes.each do |certname, current_node| + @current_collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, current_node| next if @options[:node] && certname != @options[:node] if current_node['settings']['params'].empty? output _('No currently defined settings to compare for %{role} %{certname}') % { role: current_node['role'], certname: certname } @@ -386,8 +386,10 @@ def configuration_for_node(certname) def collect_current_node(certname, role, settings) properties = { - 'role' => role, - 'settings' => settings, + 'certname' => certname, + 'order' => output_order(role), + 'role' => role, + 'settings' => settings, } @current_collected_nodes[certname] = properties end @@ -396,6 +398,8 @@ def collect_current_node(certname, role, settings) def collect_optimized_node(certname, role, node) properties = { + 'certname' => certname, + 'order' => output_order(role), 'resources' => node['resources'], 'role' => role, 'settings' => node['settings'], @@ -403,6 +407,25 @@ def collect_optimized_node(certname, role, node) @collected_nodes[certname] = properties end + # Establish an intuitive output order of hosts. + + def output_order(role) + case role + when 'Primary Master' + 1 + when 'Replica Master' + 2 + when 'Console Host' + 3 + when 'PuppetDB Host' + 4 + when 'External Database Host' + 5 + else + 9 + end + end + # Extract optimized settings common to all PE Infrastructure nodes. def collect_optimized_settings_common_to_all_nodes @@ -572,7 +595,7 @@ def output_settings_to_hiera output_error_and_exit _("Unable to create output directory: %{directory}") % { directory: hiera_directory } unless File.directory?(hiera_directory) Dir.mkdir(hiera_subdirectory) unless File.directory?(hiera_subdirectory) output_error_and_exit _("Unable to create output subdirectory: %{directory}") % { directory: hiera_subdirectory } unless File.directory?(hiera_subdirectory) - @collected_nodes.each do |certname, properties| + @collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, properties| next if @options[:node] && certname != @options[:node] next if properties['settings']['params'].empty? output_file = "#{@options[:hiera]}/nodes/#{certname}.yaml" @@ -589,7 +612,7 @@ def output_settings_to_hiera def output_settings_to_pe_conf return unless @options[:pe_conf] - @collected_nodes.each do |_certname, properties| + @collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |_certname, properties| next if @options[:node] && certname != @options[:node] next if properties['settings']['params'].empty? if @pe_conf::write(properties['settings']['params'])