summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cooke <jamescooke@users.noreply.github.com>2017-01-09 12:31:36 -0800
committerToshio Kuratomi <a.badger@gmail.com>2017-01-16 11:01:17 -0800
commit59c9a6d3c20e73641c430fdaa3f250c1ff431dcc (patch)
tree7fb23430a6f1e18f1c63930674723a85866c6b87
parent40eae0eadac97d108c71833667f1042d5e149346 (diff)
downloadansible-modules-core-59c9a6d3c20e73641c430fdaa3f250c1ff431dcc.tar.gz
Fix authorized_key crash in Python3 with remote key file (#20037)
* Decode downloaded keys bytes if Python3 * Fixes #20007 * Thanks @georgepsarakis (cherry picked from fafe5bba59163c525b82b6eaf12d0d4627a79bf7)
-rw-r--r--system/authorized_key.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/system/authorized_key.py b/system/authorized_key.py
index 4d4ef487..3f009c5d 100644
--- a/system/authorized_key.py
+++ b/system/authorized_key.py
@@ -150,6 +150,7 @@ import tempfile
import re
import shlex
+from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.urls import fetch_url
@@ -429,6 +430,9 @@ def enforce_state(module, params):
except Exception:
module.fail_json(msg=error_msg % key)
+ # resp.read gives bytes on python3, convert to native string type
+ key = to_native(key, errors='surrogate_or_strict')
+
# extract individual keys into an array, skipping blank lines and comments
key = [s for s in key.splitlines() if s and not s.startswith('#')]