# b64decode returning wrong results in slurp

**URL:** <https://forum.ansible.com/t/b64decode-returning-wrong-results-in-slurp/31405>\
**Category:** Ansible Project\
**Created:** [October 2, 2019, 7:43am UTC](https://forum.ansible.com/t/b64decode-returning-wrong-results-in-slurp/31405 "2019-10-02T07:43:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karim\_Torkmen](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@Karim\_Torkmen](https://forum.ansible.com/u/Karim_Torkmen)\
**Post date:** [October 2, 2019, 7:43am UTC](https://forum.ansible.com/t/b64decode-returning-wrong-results-in-slurp/31405/1 "2019-10-02T07:43:59Z")

</div>

Hi,  
I am using the slurp module to retrieve and decode a binary file. However, I am getting wrong output with binary starting with 1F EF BD instead of what I have in a decoded file with other tools: 1F 8B 08

- name: Read backup file content  
slurp:  
src: “/tmp/{{ file }}”  
register: slurp\_result  
delegate\_to: localhost

- name: Define file content  
set\_fact:  
content: “{{slurp\_result.content | b64decode }}”

Any idea what could be the issue?  
Thanks  
Karim

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 2, 2019, 11:30am UTC](https://forum.ansible.com/t/b64decode-returning-wrong-results-in-slurp/31405/2 "2019-10-02T11:30:26Z")

</div>

The filter b64decode doesn't support binary data, only ASCII.

Since you are getting the file from localhost you can use lookup plugin file.

{{ lookup('file', '/tmp/' ~ file) }}

---

<div class="post-metadata">

**Author:** ![Karim\_Torkmen](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@Karim\_Torkmen](https://forum.ansible.com/u/Karim_Torkmen)\
**Post date:** [October 3, 2019, 12:14pm UTC](https://forum.ansible.com/t/b64decode-returning-wrong-results-in-slurp/31405/3 "2019-10-03T12:14:23Z")

</div>

Hi Olstad,  
Thanks for your quick answer.

I have tried the lookup before and it throws some error related to utf-8. That is why I had to use slurp.  
Indeed, the file to decode is a .gz file which is received through SCP in a base64 encoded format.  
“msg”: “An unhandled exception occurred while running the lookup plugin ‘file’. Error was a \<type ‘exceptions.UnicodeDecodeError’\>, original message: ‘utf8’ codec can’t decode byte 0x8b in position 1: invalid start byte”  
Regards  
Karim

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 3, 2019, 5:33pm UTC](https://forum.ansible.com/t/b64decode-returning-wrong-results-in-slurp/31405/4 "2019-10-03T17:33:41Z")

</div>

Can you just run shell or command module with "base64 -d" on the file.
