Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions lib/bolt_dynamic_inventory/provider/vmpooler/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions spec/bolt_dynamic_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down