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
3 changes: 2 additions & 1 deletion .diataxis
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"default": "docs",
"readme": "docs/README.md",
"readme": "README.md",
"adr": "docs/adr",
"wow": "docs/wow",
"projects": "docs/_gtd"
}
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Metrics/AbcSize:
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 195
Max: 198

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ For a complete listing of various how-to guides and design decisions, see the [d
- [How to create and remove orbstack VMs from the command-line](howto_how_to_create_and_remove_orbstack_vms_from_the_command_line.md)
- [How to setup windows credentials for vmpooler](howto_how_to_setup_windows_credentials_for_vmpooler.md)
- [How to Test VMPooler Inventory Features](howto_how_to_test_vmpooler_inventory_features.md)

### Design Decisions

<!-- adrlog -->
* [ADR-0001](docs/adr/0001-extend-this-gem-to-be-a-bolt-inventory-dynamic-plugin-also.md) - Extend this gem to be a bolt inventory dynamic plugin also
* [ADR-0002](docs/adr/0002-configure-bolt-inventory-with-native-ssh-to-keep-things-simple.md) - Configure bolt inventory with native ssh to keep things simple
* [ADR-0003](docs/adr/0003-gather-inventory-metadata-via-the-cli-to-keep-things-simple.md) - Gather inventory metadata via the cli to keep things simple
* [ADR-0004](docs/adr/0004-create-dynamic-inventory-groups-based-on-hostname-regex-patterns.md) - Create dynamic inventory groups based on hostname regex patterns
* [ADR-0005](docs/adr/0005-add-role-fact-that-matches-the-group-name-making-puppet-switching-easier.md) - Add 'role' fact that matches the group name making puppet switching easier
* [ADR-0006](docs/adr/0006-extend-the-plugin-to-handle-not-only-orbstack-but-vmpooler-as-well.md) - Extend the plugin to handle not only orbstack but vmpooler as well
* [ADR-0007](docs/adr/0007-use-nmap-ssh-port-scan-for-vmpooler-vm-connectivity-filtering.md) - Use nmap SSH port scan for VMPooler VM connectivity filtering
* [ADR-0008](docs/adr/0008-query-both-abs-and-vmpooler-services-to-find-all-active-vms.md) - Query both ABS and vmpooler services to find all active VMs
* [ADR-0009](docs/adr/0009-cache-vm-data-with-smart-ttl-based-invalidation.md) - Cache VM data with smart TTL-based invalidation
* [ADR-0010](docs/adr/0010-surface-unavailable-vms-in-a-dedicated-group-instead-of-silently-dropping.md) - Surface unavailable VMs in a dedicated group instead of silently dropping
<!-- adrlogstop -->

### How-To Guides

<!-- howtolog -->
* [How to create a basic dynamic inventory plugin](docs/howto_how_to_create_a_basic_dynamic_inventory_plugin.md)
* [How to create and remove orbstack VMs from the command-line](docs/howto_how_to_create_and_remove_orbstack_vms_from_the_command_line.md)
* [How to setup the environment](docs/howto_how_to_setup_the_environment.md)
* [How to setup windows credentials for vmpooler](docs/howto_how_to_setup_windows_credentials_for_vmpooler.md)
* [How to Test VMPooler Inventory Features](docs/howto_how_to_test_vmpooler_inventory_features.md)
* [How to use as a bolt dynamic plugin](docs/howto_how_to_use_as_a_bolt_dynamic_plugin.md)
* [How to use as a gem](docs/howto_how_to_use_as_a_gem.md)
* [How to use the `role` fact](docs/howto_how_to_use_the_role_fact.md)
<!-- howtologstop -->
31 changes: 0 additions & 31 deletions docs/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
tags:
- -scope/implementation
---

# 3. Gather inventory metadata via the cli to keep things simple

Date: 2025-01-10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
tags:
- -scope/implementation
---

# 5. Add 'role' fact that matches the group name making puppet switching easier

Date: 2025-02-02
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
tags:
- -scope/implementation
---

# 7. Use nmap SSH port scan for VMPooler VM connectivity filtering

Date: 2025-10-28
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
tags:
- -scope/implementation
---

<!--
# Common Guidelines
**Orientation — capture the knowledge behind the problem (read this first):**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
tags:
- -scope/implementation
---

<!--
# Common Guidelines
**Orientation — capture the knowledge behind the problem (read this first):**
Expand Down
8 changes: 4 additions & 4 deletions docs/howto_how_to_use_as_a_gem.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ Vmpooler output:
➜ bolt_dynamic_inventory git:(development) ✗ bundle exec binv --provider=vmpooler --groups "agent:tender|normal"
---
targets:
- name: normal-meddling
uri: normal-meddling.delivery.puppetlabs.net
- name: onetime-algebra
uri: onetime-algebra.delivery.puppetlabs.net
- name: stiff-boulevard
uri: stiff-boulevard.delivery.puppetlabs.net
- name: tender-punditry
uri: tender-punditry.delivery.puppetlabs.net
- name: normal-meddling
uri: normal-meddling.delivery.puppetlabs.net
- name: unimposing-poll
uri: unimposing-poll.delivery.puppetlabs.net
groups:
Expand Down Expand Up @@ -201,13 +201,13 @@ groups:
facts:
role: linux
targets:
- tender-punditry
- normal-meddling
- tender-punditry
- name: agent
facts:
role: agent
targets:
- tender-punditry
- normal-meddling
- tender-punditry
➜ bolt_dynamic_inventory git:(development) ✗
```
5 changes: 3 additions & 2 deletions lib/bolt_dynamic_inventory/provider/orbstack/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ def parse_group_patterns(patterns)
end

def generate_targets(orbs)
orbs.map do |orb|
targets = orbs.map do |orb|
{
'name' => orb['name'],
'uri' => "#{orb['name']}@orb"
}
end
targets.sort_by { |t| t['name'] }
end

def generate_groups(orbs)
return [] if @group_patterns.empty?

target_names = orbs.map { |orb| orb['name'] }
target_names = orbs.map { |orb| orb['name'] }.sort

@group_patterns.each_with_object([]) do |pattern, groups|
matching_targets = target_names.grep(pattern[:regex])
Expand Down
11 changes: 8 additions & 3 deletions lib/bolt_dynamic_inventory/provider/vmpooler/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def merge_vm_lists(abs_vms, vmpooler_vms)

def generate_inventory(alive_vms, unavailable_vms)
targets = extract_targets(alive_vms + unavailable_vms)
alive_names = alive_vms.map { |vm| vm['hostname'].split('.').first }
unavailable_names = unavailable_vms.map { |vm| vm['hostname'].split('.').first }
alive_names = sorted_hostnames(alive_vms)
unavailable_names = sorted_hostnames(unavailable_vms)

alive_targets = targets.select { |t| alive_names.include?(t['name']) }
windows_targets, linux_targets = partition_targets_by_type(alive_targets)
Expand All @@ -174,8 +174,12 @@ def generate_inventory(alive_vms, unavailable_vms)
}
end

def sorted_hostnames(vms)
vms.map { |vm| vm['hostname'].split('.').first }.sort
end

def extract_targets(vms)
vms.map do |vm|
targets = vms.map do |vm|
vars = { 'type' => vm['type'] }
vars['ttl'] = vm['ttl'] if vm['ttl']
{
Expand All @@ -184,6 +188,7 @@ def extract_targets(vms)
'vars' => vars
}
end
targets.sort_by { |t| t['name'] }
end

def partition_targets_by_type(targets_with_type)
Expand Down
20 changes: 17 additions & 3 deletions spec/bolt_dynamic_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
describe BoltDynamicInventory::Provider::Orbstack::Inventory do
let(:mock_orbs) do
[
{ 'name' => 'agent01', 'status' => 'running' },
{ 'name' => 'agent02', 'status' => 'running' },
{ 'name' => 'webserver01', 'status' => 'running' },
{ 'name' => 'compiler01', 'status' => 'running' },
{ 'name' => 'webserver01', 'status' => 'running' }
{ 'name' => 'agent02', 'status' => 'running' },
{ 'name' => 'agent01', 'status' => 'running' }
]
end

Expand Down Expand Up @@ -66,6 +66,14 @@
'port' => 32_222
)
end

it 'sorts targets alphabetically by name' do
result = inventory.generate

expect(result['targets'].map { |t| t['name'] }).to eq(
%w[agent01 agent02 compiler01 webserver01]
)
end
end

context 'with group patterns' do
Expand Down Expand Up @@ -296,6 +304,12 @@ def stub_vmpooler_service_response(json_str)
)
end

it 'sorts targets alphabetically by name' do
expect(result['targets'].map { |t| t['name'] }).to eq(
%w[normal-meddling onetime-algebra tender-punditry]
)
end

it 'includes vars with type and ttl for each target' do
targets = result['targets']

Expand Down
Loading