# use binascii.unhexlify() in Jinja2 template

**URL:** <https://forum.ansible.com/t/use-binascii-unhexlify-in-jinja2-template/32204>\
**Category:** Ansible Project\
**Created:** [February 11, 2020, 5:32pm UTC](https://forum.ansible.com/t/use-binascii-unhexlify-in-jinja2-template/32204 "2020-02-11T17:32:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Stroder](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Michael\_Stroder](https://forum.ansible.com/u/Michael_Stroder)\
**Post date:** [February 11, 2020, 5:32pm UTC](https://forum.ansible.com/t/use-binascii-unhexlify-in-jinja2-template/32204/1 "2020-02-11T17:32:48Z")

</div>

HI!

I'm using stat task to let ansible calculate the SHA-512 checksum of a  
file on the managed node [1] which returns hex-encoded hash values.

Now I have to convert the checksum to bytes prior to base64-encoding  
this byte string.

In Python code I would use the function binascii.unhexlify(). But how to  
do this in a Jinja2 template?

(I'm doing this to implement Subresource Integrity [3].)

Thanks in advance.

Ciao, Michael.

[1] [https://docs.ansible.com/ansible/latest/modules/stat\_module.html](https://docs.ansible.com/ansible/latest/modules/stat_module.html)

[2] [https://docs.python.org/3/library/binascii.html#binascii.unhexlify](https://docs.python.org/3/library/binascii.html#binascii.unhexlify)

[3]  
[https://developer.mozilla.org/en-US/docs/Web/Security/Subresource\_Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity)
