Skip to content

Commit

Permalink
Fixes #26850 - set ansible_become_method per REX effective method
Browse files Browse the repository at this point in the history
  • Loading branch information
snagoor committed May 22, 2019
1 parent c39217c commit f2778bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/services/foreman_ansible/inventory_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def ansible_extra_options(host)

def remote_execution_options(host)
params = {
'ansible_become_method' => host_setting(host, 'remote_execution_effective_user_method'),
'ansible_user' => host_setting(host, 'remote_execution_ssh_user'),
'ansible_ssh_pass' => rex_ssh_password(host),
'ansible_sudo_pass' => rex_sudo_password(host),
Expand Down
8 changes: 8 additions & 0 deletions test/unit/services/inventory_creator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class InventoryCreatorTest < ActiveSupport::TestCase
returns(true).at_least_once
Setting.expects(:[]).with('ansible_connection').
returns('ssh').at_least_once
Setting.expects(:[]).with('remote_execution_effective_user_method').
returns('sudo').at_least_once
Setting.expects(:[]).with('remote_execution_effective_user_method').
returns('dzdo').at_least_once
Setting.expects(:[]).with('remote_execution_effective_user_method').
returns('su').at_least_once
@host.expects(:host_params).returns(extra_options).at_least_once
@template_invocation.job_invocation.expects(:password).
returns(nil).at_least_once
Expand Down Expand Up @@ -77,6 +83,8 @@ class InventoryCreatorTest < ActiveSupport::TestCase
connection_params['ansible_sudo_pass']
assert_equal Setting['ansible_winrm_server_cert_validation'],
connection_params['ansible_winrm_server_cert_validation']
assert_equal Setting['remote_execution_effective_user_method'],
connection_params['ansible_become_method']
end

test 'job invocation ssh password is passed when available' do
Expand Down

0 comments on commit f2778bd

Please sign in to comment.