From 687df97b7bb5d2a41e4837293562e8319ccd27f0 Mon Sep 17 00:00:00 2001 From: Maciej Delmanowski Date: Tue, 27 Nov 2018 21:06:24 +0100 Subject: [PATCH] Backport/2.6/48580: Do not require TTY for 'apt-key' operations (#48888) * Do not require TTY for 'apt-key' operations (#48580) The 'gpg' command supports the '--no-tty' option, which disables any use of a TTY during its execution. This parameter is sometimes required for non-interactive operation to avoid any questions for the user. The 'apt-key adv' command can pass additional parameters to the underlying 'gpg' command. This patch adds the '--no-tty' option to avoid issues with APT key imports when Ansible pipelining active, which disables the use of a dedicated TTY. (cherry picked from commit c7e22260355b4c08b6563fb98ebb6bf12dae5ff8) * Add changelog fragment about 'apt_key' no TTY fix (cherry picked from commit 7033e1dfc022fc09c006ac48c306810350308ce4) --- changelogs/fragments/48580-apt_key-no-tty.yaml | 3 +++ lib/ansible/modules/packaging/os/apt_key.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/48580-apt_key-no-tty.yaml diff --git a/changelogs/fragments/48580-apt_key-no-tty.yaml b/changelogs/fragments/48580-apt_key-no-tty.yaml new file mode 100644 index 00000000000..fe3d0f34b1a --- /dev/null +++ b/changelogs/fragments/48580-apt_key-no-tty.yaml @@ -0,0 +1,3 @@ +bugfixes: + - apt_key - Disable TTY requirement in GnuPG for the module to work correctly + when SSH pipelining is enabled (https://github.com/ansible/ansible/pull/48580) diff --git a/lib/ansible/modules/packaging/os/apt_key.py b/lib/ansible/modules/packaging/os/apt_key.py index 7f07b3b3a0e..05921a504ba 100644 --- a/lib/ansible/modules/packaging/os/apt_key.py +++ b/lib/ansible/modules/packaging/os/apt_key.py @@ -213,9 +213,9 @@ def download_key(module, url): def import_key(module, keyring, keyserver, key_id): if keyring: - cmd = "%s --keyring %s adv --keyserver %s --recv %s" % (apt_key_bin, keyring, keyserver, key_id) + cmd = "%s --keyring %s adv --no-tty --keyserver %s --recv %s" % (apt_key_bin, keyring, keyserver, key_id) else: - cmd = "%s adv --keyserver %s --recv %s" % (apt_key_bin, keyserver, key_id) + cmd = "%s adv --no-tty --keyserver %s --recv %s" % (apt_key_bin, keyserver, key_id) for retry in range(5): lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') (rc, out, err) = module.run_command(cmd, environ_update=lang_env)