New Module: binary

While implementing Ansible in my organization I found the need to write out binary files (in this case, a corosync authkey). I wanted this file to be different between my different inventories (I use Tower). My solution to this problem was to have a base64 encoded string of the binary file I wanted as a variable in Tower and I fed that base64 string into a custom module called “binary” that wrote that file out on a file system using a “dest” parameter.

My question is, will the ansible core project benefit from a module that can accept a base64 encoded string and write it out to the filesystem? If so I can modify my module to conform to the project standards and submit a pull request. Or maybe I’m even duplicating the efforts of another module? Googling didn’t help when I was looking for a way to write out a binary file.

It looks like the copy module uses jinja to write out what was passed to it via “content”. Since this is a binary file, jinja fails:

fatal: [sf-web01] => Traceback (most recent call last):
File “/usr/lib/python2.6/site-packages/ansible/runner/init.py”, line 561, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/usr/lib/python2.6/site-packages/ansible/runner/init.py”, line 666, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File “/usr/lib/python2.6/site-packages/ansible/runner/init.py”, line 870, in _executor_internal_inner
module_args = template.template(self.basedir, module_args, inject, fail_on_undefined=self.error_on_undefined_vars)
File “/usr/lib/python2.6/site-packages/ansible/utils/template.py”, line 115, in template
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
File “/usr/lib/python2.6/site-packages/ansible/utils/template.py”, line 357, in template_from_string
res = jinja2.utils.concat(rf)
File “”, line 10, in root
File “/usr/lib64/python2.6/encodings/utf_8.py”, line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa9 in position 0: invalid start byte

fatal: [sf-web02] => Traceback (most recent call last):
File “/usr/lib/python2.6/site-packages/ansible/runner/init.py”, line 561, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/usr/lib/python2.6/site-packages/ansible/runner/init.py”, line 666, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File “/usr/lib/python2.6/site-packages/ansible/runner/init.py”, line 870, in _executor_internal_inner
module_args = template.template(self.basedir, module_args, inject, fail_on_undefined=self.error_on_undefined_vars)
File “/usr/lib/python2.6/site-packages/ansible/utils/template.py”, line 115, in template
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
File “/usr/lib/python2.6/site-packages/ansible/utils/template.py”, line 357, in template_from_string
res = jinja2.utils.concat(rf)
File “”, line 10, in root
File “/usr/lib64/python2.6/encodings/utf_8.py”, line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa9 in position 0: invalid start byte

If there is another way for me to accomplish this using the built-in modules, please let me know.