From fd61e817648d21d847fb9d972a368195359dd0f9 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Tue, 17 May 2016 19:21:55 +0200 Subject: [PATCH] Port authorized_keys to a syntax compatible with python3 and 2.4 (#3677) --- lib/ansible/modules/system/authorized_key.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/system/authorized_key.py b/lib/ansible/modules/system/authorized_key.py index dfb0b1b207..b59b469665 100644 --- a/lib/ansible/modules/system/authorized_key.py +++ b/lib/ansible/modules/system/authorized_key.py @@ -185,7 +185,8 @@ def keyfile(module, user, write=False, path=None, manage_dir=True): try: user_entry = pwd.getpwnam(user) - except KeyError, e: + except KeyError: + e = get_exception() if module.check_mode and path is None: module.fail_json(msg="Either user must exist or you must provide full path to key file in check mode") module.fail_json(msg="Failed to lookup user %s: %s" % (user, str(e))) @@ -205,11 +206,11 @@ def keyfile(module, user, write=False, path=None, manage_dir=True): if manage_dir: if not os.path.exists(sshdir): - os.mkdir(sshdir, 0700) + os.mkdir(sshdir, int('0700', 8)) if module.selinux_enabled(): module.set_default_selinux_context(sshdir, False) os.chown(sshdir, uid, gid) - os.chmod(sshdir, 0700) + os.chmod(sshdir, int('0700', 8)) if not os.path.exists(keysfile): basedir = os.path.dirname(keysfile) @@ -224,7 +225,7 @@ def keyfile(module, user, write=False, path=None, manage_dir=True): try: os.chown(keysfile, uid, gid) - os.chmod(keysfile, 0600) + os.chmod(keysfile, int('0600', 8)) except OSError: pass @@ -349,7 +350,8 @@ def writekeys(module, filename, keys): except: key_line = key f.writelines(key_line) - except IOError, e: + except IOError: + e = get_exception() module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, str(e))) f.close() module.atomic_move(tmp_path, filename)