Skip to content

b64encode

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version historical.

Synopsis

  • Base64 encoding function.

Parameters

Parameter Defaults / Choices Comments
_input
string
required
A string to encode.
encoding
string
The encoding to use to transform from a text string to a byte string.
Defaults to using 'utf-8'.
urlsafe
bool
Encode 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 encode a string
b64lola: "{{ 'lola'| b64encode }}"

# Base64 encode the content of 'stuff' variable
b64stuff: "{{ stuff | b64encode }}"

# Base64 encode the content with different encoding
b64stuff: "{{ 'Ansible - くらとみ\n' | b64encode(encoding='utf-16-le') }}"
# => 'QQBuAHMAaQBiAGwAZQAgAC0AIABPMIkwaDB/MAoA'

# URL-safe Base64 encoding
b64stuff: "{{ 'https://www.python.org/example-1' | b64encode(urlsafe=True) }}"
# => 'aHR0cHM6Ly93d3cucHl0aG9uLm9yZy9leGFtcGxlLTE='

Return Values

Key Data Type Description Returned
_value string A Base64 encoded string.

Authors

  • Ansible Core Team