b64decode returning wrong results in slurp

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

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) }}

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

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