Skip to content

Commit

Permalink
Merge pull request #18724 from djberg96/conversion_host_ansible_playb…
Browse files Browse the repository at this point in the history
…ook_default_credentials

[V2V] Add default credentials to ansible_playbook method

(cherry picked from commit a68811e)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1694229
  • Loading branch information
agrare authored and simaishi committed May 8, 2019
1 parent 9d0322d commit e9beef7
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,23 @@ def resource_supports_conversion_host
end

# Find the credentials for the associated resource. By default it will
# look for a v2v auth type. If that is not found, it will look for the
# authentication associated with the resource using ssh_keypair or default,
# in that order, as the authtype.
# look for a v2v auth type if no argument is passed in.
#
def find_credentials(msg = nil)
authentication = authentication_type('v2v') ||
resource.authentication_type('ssh_keypair') ||
resource.authentication_type('default')
# If one isn't found, then it will look for the authentication associated
# with the resource using the 'ssh_keypair' auth type, and finally 'default'.
#
def find_credentials(auth_type = 'v2v')
authentication = authentication_type(auth_type)

if authentication.blank?
res = resource.respond_to?(:authentication_type) ? resource : resource.ext_management_system
authentication = res.authentication_type('ssh_keypair') || res.authentication_type('default')
end

unless authentication
msg = "Credentials not found for conversion host #{name} or resource #{resource.name}"
msg << " #{msg}" if msg
_log.error(msg)
raise MiqException::Error, msg
error_msg = "Credentials not found for conversion host #{name} or resource #{resource.name}"
_log.error(error_msg)
raise MiqException::Error, error_msg
end

authentication
Expand Down Expand Up @@ -249,7 +252,7 @@ def ansible_playbook(playbook, extra_vars = {}, miq_task_id = nil, auth_type = n

command = "ansible-playbook #{playbook} --inventory #{host}, --become --extra-vars=\"ansible_ssh_common_args='-o StrictHostKeyChecking=no'\""

auth = authentication_type(auth_type) || authentications.first
auth = find_credentials(auth_type)
command << " --user #{auth.userid}"

case auth
Expand Down

0 comments on commit e9beef7

Please sign in to comment.