Hi,
while working on a module, I have the problem that I need to return
proper binary data (something like random bytes) to the user; the user
has to register the result to use it. The user then has to process this
data somehow, usually by passing it along (write it into a file, pass
it to another module, ...). This worked fine so far for me locally (with
Python 3), but now that I added tests, it breaks for Python 2. I guess
somewhere in the process, some conversion (UTF-8 <-> whatever) is done,
and the data is corrupted.
Maybe I'm doing something wrong somewhere, but in general: is there a
good / suggested / Ansible specific way to handle binary data in
playbook variables, or as return values of modules?
I first though about returning the data Base64 encoded, but I'm not
sure whether that's the best solution, especially if the user has to
pass it to another Ansible module.
The PR in question is https://github.com/ansible/ansible/pull/42158
(ACME: support for TLS-ALPN-01). The binary data is generated by
hashlib.sha256().digest(), and is of type str in Python 2 and of type
bytes in Python 3.
(https://github.com/ansible/ansible/pull/42158/files#diff-bcd36cbc1ccdcaf6d84c28c69bfb1dd1R494)
Thanks for any hints / suggestions / ideas on how to handle binary data!
All the best,
Felix