b64decode¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in versionhistorical.
Synopsis¶
- Base64 decoding function.
- The return value is a string.
- Trying to store a binary blob in a string most likely corrupts the binary. To Base64 decode a binary blob, use the I(base64) command and pipe the encoded data through standard input. For example, in the M(ansible.builtin.shell) module,
cmd="base64 --decode > myfile.bin" stdin="{{ encoded }}".
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input string required |
A Base64 string to decode. | |
| encoding string |
The encoding to use to transform from a text string to a byte string. Defaults to using 'utf-8'. |
|
| urlsafe bool |
Decode string using URL- and filesystem-safe alphabet, which substitutes I(-) instead of I(+) and I(_) instead of I(/) in the Base64 alphabet. Version Added: 2.19 |
Examples¶
# Base64 decode a string
lola: "{{ 'bG9sYQ==' | b64decode }}"
# Base64 decode the content of 'b64stuff' variable
stuff: "{{ b64stuff | b64decode }}"
# Base64 decode the content with different encoding
stuff: "{{ 'QQBuAHMAaQBiAGwAZQAgAC0AIABPMIkwaDB/MAoA' | b64decode(encoding='utf-16-le') }}"
# => 'Ansible - くらとみ\n'
# URL-Safe Base64 decoding
stuff: "{{ 'aHR0cHM6Ly93d3cucHl0aG9uLm9yZy9leGFtcGxlLTE=' | b64decode(urlsafe=True) }}"
# => 'https://www.python.org/example-1'
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | string | The contents of the Base64 encoded string. |
Authors¶
- Ansible Core Team