Skip to content

Commit

Permalink
Fixes #26850 - set ansible_become_method per REX effective method (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
snagoor authored and ares committed Aug 8, 2019
1 parent 0df6db1 commit cebfe4d
Show file tree
Hide file tree
Showing 2 changed files with 7 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 @@ -100,6 +100,7 @@ def remote_execution_options(host)
'ansible_user' => host_setting(host, 'remote_execution_ssh_user'),
'ansible_ssh_pass' => rex_ssh_password(host),
'ansible_sudo_pass' => rex_sudo_password(host),
'ansible_become_method' => host_setting(host, 'remote_execution_effective_user_method'),
'ansible_ssh_private_key_file' => ansible_or_rex_ssh_private_key(host),
'ansible_port' => host_setting(host, 'remote_execution_ssh_port'),
'ansible_host' => AnsibleProvider.find_ip_or_hostname(host)
Expand Down
6 changes: 6 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,8 @@ 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
@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 +79,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 Expand Up @@ -105,6 +109,8 @@ class InventoryCreatorTest < ActiveSupport::TestCase
returns('root')
host.params.expects(:[]).with('remote_execution_ssh_port').
returns('2222')
host.params.expects(:[]).with('remote_execution_effective_user_method').
returns('sudo')
connection_params = inventory.connection_params(host)
assert_equal path_to_key,
connection_params['ansible_ssh_private_key_file']
Expand Down

0 comments on commit cebfe4d

Please sign in to comment.