From 56edbd2bbb372a61dae2017923f1d8e33d1922d9 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 11 Feb 2022 16:26:02 -0500 Subject: [PATCH] Handle connection dissonance (#77005) * play_context, compensate for existing plugins some connection plugins are not fully using the correct configuration, but this was previously hidden from them as play_context was providing the info instead, now play_context provides the 'correct' info, but hitting these bad configurations. --- changelogs/fragments/handle_connection_cornercase.yml | 2 ++ lib/ansible/playbook/play_context.py | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 changelogs/fragments/handle_connection_cornercase.yml diff --git a/changelogs/fragments/handle_connection_cornercase.yml b/changelogs/fragments/handle_connection_cornercase.yml new file mode 100644 index 00000000000..2fec19f2068 --- /dev/null +++ b/changelogs/fragments/handle_connection_cornercase.yml @@ -0,0 +1,2 @@ +bugfixes: + - play_context now compensates for when a conneciton sets the default to inventory_hostname but skips adding it to the vars. diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 21bd84c0256..1918a1931e6 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -297,6 +297,13 @@ class PlayContext(Base): if not new_info.connection_user: new_info.connection_user = new_info.remote_user + # for case in which connection plugin still uses pc.remote_addr and in it's own options + # specifies 'default: inventory_hostname', but never added to vars: + if new_info.remote_addr == 'inventory_hostname': + new_info.remote_addr = variables.get('inventory_hostname') + display.warning('The "%s" connection plugin has an improperly configured remote target value, ' + 'forcing "inventory_hostname" templated value instead of the string' % new_info.connection) + # set no_log to default if it was not previously set if new_info.no_log is None: new_info.no_log = C.DEFAULT_NO_LOG