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

Fixes #26850 - set ansible_become_method per REX effective method #271

Merged
merged 1 commit into from
Aug 8, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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