write need bytes object on python 3 (#35143)

Otherwise, it fail with:

    Traceback (most recent call last):
      File \"/tmp/ansible_c1zmq3i9/ansible_module_openssl_certificate.py\", line 808, in <module>
        main()
      File \"/tmp/ansible_c1zmq3i9/ansible_module_openssl_certificate.py\", line 787, in main
        certificate.generate(module)
      File \"/tmp/ansible_c1zmq3i9/ansible_module_openssl_certificate.py\", line 692, in generate
        certfile.write(str(crt))
    TypeError: a bytes-like object is required, not 'str'

(cherry picked from commit 347b5d1e50)
This commit is contained in:
Michael Scherer 2018-01-21 12:26:32 +01:00 committed by Toshio Kuratomi
parent 02e591746c
commit 0f8b06a8f6

View file

@ -689,7 +689,7 @@ class AcmeCertificate(Certificate):
'--acme-dir', self.challenge_path], stdout=subprocess.PIPE)
crt = p.communicate()[0]
with open(self.path, 'wb') as certfile:
certfile.write(str(crt))
certfile.write(to_bytes(crt))
except OSError as exc:
raise CertificateError(exc)