From 708bda06aa5cceaea5ead1e881a52b5adbc4d424 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 19 May 2019 14:00:25 +0200 Subject: [PATCH] docker connection plugin: make privilege escalation code more similar to local.py (#56288) * Make more similar to local.py * Fix typo. --- .../fragments/53385-docker-privilege-escalation.yml | 2 +- lib/ansible/plugins/connection/docker.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelogs/fragments/53385-docker-privilege-escalation.yml b/changelogs/fragments/53385-docker-privilege-escalation.yml index 6c7f7678fe..f727d794d1 100644 --- a/changelogs/fragments/53385-docker-privilege-escalation.yml +++ b/changelogs/fragments/53385-docker-privilege-escalation.yml @@ -1,4 +1,4 @@ --- bugfixes: - Fix privilege escalation support for the docker connection plugin when - credentials needs to be supplied (e.g. sudo with password). + credentials need to be supplied (e.g. sudo with password). diff --git a/lib/ansible/plugins/connection/docker.py b/lib/ansible/plugins/connection/docker.py index 05d4336da9..d6d3518630 100644 --- a/lib/ansible/plugins/connection/docker.py +++ b/lib/ansible/plugins/connection/docker.py @@ -205,7 +205,9 @@ class Connection(ConnectionBase): local_cmd = self._build_exec_cmd([self._play_context.executable, '-c', cmd]) - display.vvv("EXEC %s" % (local_cmd,), host=self._play_context.remote_addr) + display.vvv(u"EXEC {0}".format(to_text(local_cmd)), host=self._play_context.remote_addr) + display.debug("opening command with Popen()") + local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd] p = subprocess.Popen( @@ -214,12 +216,11 @@ class Connection(ConnectionBase): stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) + display.debug("done running command with Popen()") if self.become and self.become.expect_prompt() and sudoable: - display.debug("handling privilege escalation") fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) fcntl.fcntl(p.stderr, fcntl.F_SETFL, fcntl.fcntl(p.stderr, fcntl.F_GETFL) | os.O_NONBLOCK) - selector = selectors.DefaultSelector() selector.register(p.stdout, selectors.EVENT_READ) selector.register(p.stderr, selectors.EVENT_READ) @@ -235,7 +236,6 @@ class Connection(ConnectionBase): for key, event in events: if key.fileobj == p.stdout: chunk = p.stdout.read() - break elif key.fileobj == p.stderr: chunk = p.stderr.read()