# New Module: binary

**URL:** <https://forum.ansible.com/t/new-module-binary/16779>\
**Category:** Ansible Developer\
**Created:** [November 13, 2014, 9:19pm UTC](https://forum.ansible.com/t/new-module-binary/16779 "2014-11-13T21:19:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derek\_Anderson](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Derek\_Anderson](https://forum.ansible.com/u/Derek_Anderson)\
**Post date:** [November 13, 2014, 9:19pm UTC](https://forum.ansible.com/t/new-module-binary/16779/1 "2014-11-13T21:19:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [November 13, 2014, 10:14pm UTC](https://forum.ansible.com/t/new-module-binary/16779/2 "2014-11-13T22:14:16Z")

</div>

>

---

<div class="post-metadata">

**Author:** ![Derek\_Anderson](https://avatars.discourse-cdn.com/v4/letter/d/ea666f/32.png) [@Derek\_Anderson](https://forum.ansible.com/u/Derek_Anderson)\
**Post date:** [November 14, 2014, 2:31pm UTC](https://forum.ansible.com/t/new-module-binary/16779/3 "2014-11-14T14:31:53Z")

</div>

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.
