From 80361ce4da747547fac3b6ab823c900479117257 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 17 Jan 2018 11:27:12 +0100 Subject: [PATCH] Making letsencrypt module work with Python 3. (#34324) --- lib/ansible/modules/web_infrastructure/letsencrypt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/letsencrypt.py b/lib/ansible/modules/web_infrastructure/letsencrypt.py index cd057acbec6..bff44f65b8b 100644 --- a/lib/ansible/modules/web_infrastructure/letsencrypt.py +++ b/lib/ansible/modules/web_infrastructure/letsencrypt.py @@ -252,7 +252,7 @@ def get_cert_days(module, cert_file): openssl_bin = module.get_bin_path('openssl', True) openssl_cert_cmd = [openssl_bin, "x509", "-in", cert_file, "-noout", "-text"] - _, out, _ = module.run_command(openssl_cert_cmd, check_rc=True) + _, out, _ = module.run_command(openssl_cert_cmd, check_rc=True, encoding=None) try: not_after_str = re.search(r"\s+Not After\s*:\s+(.*)", out.decode('utf8')).group(1) not_after = datetime.fromtimestamp(time.mktime(time.strptime(not_after_str, '%b %d %H:%M:%S %Y %Z'))) @@ -375,7 +375,7 @@ class ACMEAccount(object): module.add_cleanup_file(tmpsrc) # Ansible will delete the file on exit f = open(tmpsrc, 'wb') try: - f.write(self.key_content) + f.write(self.key_content.encode('utf-8')) self.key = tmpsrc except Exception as err: os.remove(tmpsrc) @@ -843,7 +843,7 @@ class ACMEClient(object): new_cert = { "resource": "new-cert", - "csr": nopad_b64(out), + "csr": nopad_b64(to_bytes(out)), } result, info = self.account.send_signed_request(self.directory['new-cert'], new_cert) @@ -917,7 +917,7 @@ class ACMEClient(object): if chain and self.module.params['fullchain']: pem_cert += "\n".join(chain) - if write_file(self.module, self.dest, pem_cert): + if write_file(self.module, self.dest, pem_cert.encode('utf8')): self.cert_days = get_cert_days(self.module, self.dest) self.changed = True