Skip to content

Commit

Permalink
Fix authorized_key crash in Python3 with remote key file (ansible#20037)
Browse files Browse the repository at this point in the history
* Decode downloaded keys bytes if Python3
* Fixes ansible#20007
* Thanks @georgepsarakis
  • Loading branch information
jamescooke authored and abadger committed Jan 9, 2017
1 parent b8ee80a commit fafe5bb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ansible/modules/system/authorized_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
import shlex
from operator import itemgetter

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
Expand Down Expand Up @@ -537,6 +538,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
new_keys = [s for s in key.splitlines() if s and not s.startswith('#')]

Expand Down

0 comments on commit fafe5bb

Please sign in to comment.