From 1ba83b4a21f0d930935a3291473f29f392336796 Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Mon, 3 Nov 2025 15:50:13 +0000 Subject: [PATCH 1/3] Add os type var This adds the vmpooler OS type as a variable to the inventory output so I can select a host by OS. Signed-off-by: Gavin Didrichsen --- .../provider/vmpooler/inventory.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/bolt_dynamic_inventory/provider/vmpooler/inventory.rb b/lib/bolt_dynamic_inventory/provider/vmpooler/inventory.rb index b512bb5..eacc28a 100644 --- a/lib/bolt_dynamic_inventory/provider/vmpooler/inventory.rb +++ b/lib/bolt_dynamic_inventory/provider/vmpooler/inventory.rb @@ -100,10 +100,9 @@ def fetch_vmpooler_vms # Generate the Bolt inventory structure def generate_inventory(vms) - targets_with_type = extract_targets_with_type(vms) - target_names = targets_with_type.map { |t| t['name'] } - windows_targets, linux_targets = partition_targets_by_type(targets_with_type) - targets = targets_with_type.map { |t| t.except('type') } + targets = extract_targets_with_type(vms) + target_names = targets.map { |t| t['name'] } + windows_targets, linux_targets = partition_targets_by_type(targets) { 'targets' => targets, @@ -116,14 +115,16 @@ def extract_targets_with_type(vms) { 'name' => vm['hostname'].split('.').first, 'uri' => vm['hostname'], - 'type' => vm['type'] + 'vars' => { + 'type' => vm['type'] + } } end end def partition_targets_by_type(targets_with_type) - windows = targets_with_type.select { |t| t['type'].include?('win') }.map { |t| t['name'] } - linux = targets_with_type.reject { |t| t['type'].include?('win') }.map { |t| t['name'] } + windows = targets_with_type.select { |t| t['vars']['type'].include?('win') }.map { |t| t['name'] } + linux = targets_with_type.reject { |t| t['vars']['type'].include?('win') }.map { |t| t['name'] } [windows, linux] end From 6e9283146fcefb592a4bf836459036ac8a71d3bb Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Mon, 3 Nov 2025 15:50:29 +0000 Subject: [PATCH 2/3] Fix rubocop warning. Signed-off-by: Gavin Didrichsen --- .rubocop_todo.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f25e2b5..3b7c3ea 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-10-28 17:42:57 UTC using RuboCop version 1.76.2. +# on 2025-11-03 15:48:25 UTC using RuboCop version 1.76.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -22,7 +22,7 @@ Metrics/AbcSize: # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 127 + Max: 128 # Offense count: 1 # Configuration parameters: AllowedMethods, AllowedPatterns. From 4fa335b35d819551b0089d6da0d17bee80554efe Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Mon, 3 Nov 2025 15:57:29 +0000 Subject: [PATCH 3/3] Add test for the new target structure Signed-off-by: Gavin Didrichsen --- spec/bolt_dynamic_inventory_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/bolt_dynamic_inventory_spec.rb b/spec/bolt_dynamic_inventory_spec.rb index 872648f..487388c 100644 --- a/spec/bolt_dynamic_inventory_spec.rb +++ b/spec/bolt_dynamic_inventory_spec.rb @@ -254,6 +254,19 @@ ) end + it 'includes vars with type for each target' do + targets = result['targets'] + + onetime_target = targets.find { |t| t['name'] == 'onetime-algebra' } + expect(onetime_target['vars']).to eq('type' => 'win-2019-x86_64') + + tender_target = targets.find { |t| t['name'] == 'tender-punditry' } + expect(tender_target['vars']).to eq('type' => 'ubuntu-2004-x86_64') + + normal_target = targets.find { |t| t['name'] == 'normal-meddling' } + expect(normal_target['vars']).to eq('type' => 'ubuntu-2004-x86_64') + end + it 'configures windows group correctly' do windows_group = result['groups'].find { |g| g['name'] == 'windows' } expect(windows_group['targets']).to contain_exactly('onetime-algebra')