From b46ce47a84085da66272c6194d00f9e527a7d2a9 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 20 Oct 2015 14:02:39 -0400 Subject: [PATCH] Don't use local transport for delegated hosts if the inventory_hostname isn't local For some situations like Vagrant, the remote_addr may be a localhost addr, but ssh is still desired. This corrects the assumption that any localhost remote_addr should be using the local connection by checking the inventory_hostname value as well. Fixes #12817 --- lib/ansible/playbook/play_context.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 67a62b4871..fbf54853f2 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -357,9 +357,11 @@ class PlayContext(Base): if connection_type in delegated_vars: break else: - if new_info.remote_addr in C.LOCALHOST: + remote_addr_local = new_info.remote_addr in C.LOCALHOST + inv_hostname_local = delegated_vars.get('inventory_hostname') in C.LOCALHOST + if remote_addr_local and inv_hostname_local: setattr(new_info, 'connection', 'local') - elif getattr(new_info, 'connection', None) == 'local' and new_info.remote_addr not in C.LOCALHOST: + elif getattr(new_info, 'connection', None) == 'local' and (not remote_addr_local or not inv_hostname_local): setattr(new_info, 'connection', C.DEFAULT_TRANSPORT) # set no_log to default if it was not previouslly set