From 5d58a7cadb5f2000013aa712ce88962eaee1eab9 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 11 Apr 2019 14:32:52 -0400 Subject: [PATCH] Correct plugin loader context for persistent (#54860) * Correct plugin loader context for persistent (cherry picked from commit 6579dfda1717cda64bdb2a6de31f0b8ec7841471) --- changelogs/fragments/persistent_loading.yml | 2 ++ lib/ansible/plugins/connection/persistent.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/persistent_loading.yml diff --git a/changelogs/fragments/persistent_loading.yml b/changelogs/fragments/persistent_loading.yml new file mode 100644 index 00000000000..9c132c5788b --- /dev/null +++ b/changelogs/fragments/persistent_loading.yml @@ -0,0 +1,2 @@ +bugfixes: + - pass correct loading context to persistent connections diff --git a/lib/ansible/plugins/connection/persistent.py b/lib/ansible/plugins/connection/persistent.py index 800a42843c5..10f4d80c3d2 100644 --- a/lib/ansible/plugins/connection/persistent.py +++ b/lib/ansible/plugins/connection/persistent.py @@ -37,6 +37,7 @@ import sys import termios from ansible import constants as C +from ansible.plugins.loader import become_loader, cliconf_loader, connection_loader, httpapi_loader, netconf_loader, terminal_loader from ansible.plugins.connection import ConnectionBase from ansible.module_utils._text import to_text from ansible.module_utils.connection import Connection as SocketConnection, write_to_file_descriptor @@ -93,6 +94,15 @@ class Connection(ConnectionBase): ''' master, slave = pty.openpty() + env = os.environ.copy() + env.update({ + 'ANSIBLE_BECOME_PLUGINS': become_loader.print_paths(), + 'ANSIBLE_CLICONF_PLUGINS': cliconf_loader.print_paths(), + 'ANSIBLE_CONNECTION_PLUGINS': connection_loader.print_paths(), + 'ANSIBLE_HTTPAPI_PLUGINS': httpapi_loader.print_paths(), + 'ANSIBLE_NETCONF_PLUGINS': netconf_loader.print_paths(), + 'ANSIBLE_TERMINAL_PLUGINS': terminal_loader.print_paths(), + }) python = sys.executable def find_file_in_path(filename): @@ -107,7 +117,7 @@ class Connection(ConnectionBase): p = subprocess.Popen( [python, find_file_in_path('ansible-connection'), to_text(os.getppid())], - stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE + stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env ) os.close(slave)