Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-3309) Ensure bundled-ruby defaults are applied at target init #3313

Merged
merged 1 commit into from
May 13, 2024
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: 3 additions & 1 deletion lib/bolt/inventory/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(target_data, inventory)
@name = @uri
@safe_name = @uri_obj.omit(:password).to_str.sub(%r{^//}, '')
end

# handle special localhost target
if @name == 'localhost'
default = { 'config' => { 'transport' => 'local' } }
target_data = Bolt::Util.deep_merge(default, target_data)
Expand All @@ -53,6 +53,8 @@ def initialize(target_data, inventory)
@inventory = inventory

validate
# after setting config, apply local defaults when using bundled ruby
set_local_defaults if transport_config['bundled-ruby']
end

def set_local_defaults
Expand Down
4 changes: 0 additions & 4 deletions lib/bolt/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ def resources
inventory_target.resources
end

def set_local_defaults
inventory_target.set_local_defaults
end

# rubocop:disable Naming/AccessorMethodName
def set_resource(resource)
inventory_target.set_resource(resource)
Expand Down
4 changes: 0 additions & 4 deletions lib/bolt/transport/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def connected?(_target)
end

def with_connection(target)
if target.transport_config['bundled-ruby']
target.set_local_defaults
end

yield Connection.new(target)
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/transport/local_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def get_target(inventory, name, alia = nil)
end
end

context 'without with_connection' do
let(:data) { { 'targets' => [] } }
it 'applies bundled-ruby config' do
target = get_target(inventory, 'local://foo')
expect(target.transport).to eq('local')
expect(target.options['interpreters']).to include('.rb' => RbConfig.ruby)
expect(target.features).to include('puppet-agent')
end
end

context 'with group-level config' do
let(:data) {
{ 'targets' => [uri],
Expand Down
Loading