Merge pull request #9702 from bcoca/better_errors_on_delegate

better exception handling with delegated hosts
pull/10025/head
Brian Coca 10 years ago
commit 2ef5d6be1e

@ -420,7 +420,7 @@ class Inventory(object):
group = self.get_group(groupname) group = self.get_group(groupname)
if group is None: if group is None:
raise Exception("group not found: %s" % groupname) raise errors.AnsibleError("group not found: %s" % groupname)
vars = {} vars = {}
@ -439,7 +439,7 @@ class Inventory(object):
host = self.get_host(hostname) host = self.get_host(hostname)
if not host: if not host:
raise Exception("host not found: %s" % hostname) raise errors.AnsibleError("host not found: %s" % hostname)
return host.get_variables() return host.get_variables()
def get_host_variables(self, hostname, update_cached=False, vault_password=None): def get_host_variables(self, hostname, update_cached=False, vault_password=None):

@ -394,20 +394,20 @@ class Runner(object):
actual_user = inject.get('ansible_ssh_user', self.remote_user) actual_user = inject.get('ansible_ssh_user', self.remote_user)
thisuser = None thisuser = None
if host in inject['hostvars']: try:
if inject['hostvars'][host].get('ansible_ssh_user'): if host in inject['hostvars']:
# user for delegate host in inventory if inject['hostvars'][host].get('ansible_ssh_user'):
thisuser = inject['hostvars'][host].get('ansible_ssh_user') # user for delegate host in inventory
else: thisuser = inject['hostvars'][host].get('ansible_ssh_user')
# look up the variables for the host directly from inventory else:
try: # look up the variables for the host directly from inventory
host_vars = self.inventory.get_variables(host, vault_password=self.vault_pass) host_vars = self.inventory.get_variables(host, vault_password=self.vault_pass)
if 'ansible_ssh_user' in host_vars: if 'ansible_ssh_user' in host_vars:
thisuser = host_vars['ansible_ssh_user'] thisuser = host_vars['ansible_ssh_user']
except Exception, e: except errors.AnsibleError, e:
# the hostname was not found in the inventory, so # the hostname was not found in the inventory, so
# we just ignore this and try the next method # we just ignore this and try the next method
pass pass
if thisuser is None and self.remote_user: if thisuser is None and self.remote_user:
# user defined by play/runner # user defined by play/runner

Loading…
Cancel
Save