From 1f73bef85613a1f994df137efec2b3c4fb2b822b Mon Sep 17 00:00:00 2001 From: mattymo Date: Wed, 22 Jun 2016 08:42:44 +0300 Subject: [PATCH] Add retries to apt_key with keyserver, fixes #3986 (#3987) Public SKS gpg servers frequently are unavailable, but a retry can mitigate frequent failures. --- packaging/os/apt_key.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packaging/os/apt_key.py b/packaging/os/apt_key.py index bc8cb80b5c8..09679853f8f 100644 --- a/packaging/os/apt_key.py +++ b/packaging/os/apt_key.py @@ -171,7 +171,14 @@ def import_key(module, keyring, keyserver, key_id): cmd = "apt-key --keyring %s adv --keyserver %s --recv %s" % (keyring, keyserver, key_id) else: cmd = "apt-key adv --keyserver %s --recv %s" % (keyserver, key_id) - (rc, out, err) = module.run_command(cmd, check_rc=True) + for retry in xrange(5): + (rc, out, err) = module.run_command(cmd) + if rc == 0: + break + else: + # Out of retries + module.fail_json(cmd=cmd, msg="error fetching key from keyserver: %s" % keyserver, + rc=rc, stdout=out, stderr=err) return True def add_key(module, keyfile, keyring, data=None):