summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2023-03-06 16:14:35 -0500
committerGitHub <noreply@github.com>2023-03-06 16:14:35 -0500
commitca604513dbd8f7db590399f031a12dec38cd90d3 (patch)
tree9fcb124fb40bab3cd21d75c846f07d8c994b70e4
parentff3ee9c4bdac68909bcb769091a198a7c45e6350 (diff)
downloadansible-ca604513dbd8f7db590399f031a12dec38cd90d3.tar.gz
apt_repository, dont assume only missing apt-key will populate stderr (#79827)
fixes #79825
-rw-r--r--changelogs/fragments/apt_repo_fix.yml2
-rw-r--r--lib/ansible/modules/apt_repository.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/changelogs/fragments/apt_repo_fix.yml b/changelogs/fragments/apt_repo_fix.yml
new file mode 100644
index 0000000000..fd3712d556
--- /dev/null
+++ b/changelogs/fragments/apt_repo_fix.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - apt_repository will no longer fail to detect key when unrelated errors/warnings are issued by apt-key.
diff --git a/lib/ansible/modules/apt_repository.py b/lib/ansible/modules/apt_repository.py
index e4a957b32d..2718137e35 100644
--- a/lib/ansible/modules/apt_repository.py
+++ b/lib/ansible/modules/apt_repository.py
@@ -184,6 +184,8 @@ from ansible.module_utils._text import to_native
from ansible.module_utils.six import PY3
from ansible.module_utils.urls import fetch_url
+from ansible.module_utils.common.locale import get_best_parsable_locale
+
try:
import apt
import apt_pkg
@@ -491,8 +493,11 @@ class UbuntuSourcesList(SourcesList):
def _key_already_exists(self, key_fingerprint):
if self.apt_key_bin:
+ locale = get_best_parsable_locale(self.module)
+ APT_ENV = dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale, LC_CTYPE=locale)
+ self.module.run_command_environ_update = APT_ENV
rc, out, err = self.module.run_command([self.apt_key_bin, 'export', key_fingerprint], check_rc=True)
- found = len(err) == 0
+ found = bool(not err or 'nothing exported' not in err)
else:
found = self._gpg_key_exists(key_fingerprint)