Some of our passwords contain the backtick character.
This issue prevents us from using them with the shell or script module when passed as parameter in a variable.
# ansible --version
ansible [core 2.21.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/ansible/venv/lib/python3.14/site-packages/ansible
ansible collection location = /opt
executable location = /opt/ansible/venv/bin/ansible
python version = 3.14.4 (main, Apr 8 2026, 04:02:31) [GCC 15.2.0] (/opt/ansible/venv/bin/python3.14)
jinja version = 3.1.6
pyyaml version = 6.0.3 (with libyaml v0.2.5)
EDITED to reflect the modified title
- shell:
cmd: |
echo "'`'"
executable: /bin/bash
leads to: unexpected EOF while looking for matching ``
[ERROR]: Task failed: Module failed: The command exited with a non-zero return code.
Origin: /roles/test/tasks/backtick.yml:36:3
34 ##################################################################################################################...
35
36 - shell:
^ column 3
Traceback (most recent call last):
File "<stdin>", line 266, in <module>
File "<stdin>", line 260, in _ansiballz_main
File "<stdin>", line 140, in invoke_module
File "/tmp/ansible_ansible.legacy.command_payload_2jqknp9u/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/_internal/_ansiballz/_loader.py", line 35, in run_module
_run_module(
File "/tmp/ansible_ansible.legacy.command_payload_2jqknp9u/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/_internal/_ansiballz/_loader.py", line 62, in _run_module
runpy.run_module(mod_name=module_fqn, init_globals=init_globals, run_name='__main__', alter_sys=True)
File "<frozen runpy>", line 226, in run_module
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "/tmp/ansible_ansible.legacy.command_payload_2jqknp9u/ansible_ansible.legacy.command_payload.zip/ansible/modules/command.py", line 367, in <module>
main()
File "/tmp/ansible_ansible.legacy.command_payload_2jqknp9u/ansible_ansible.legacy.command_payload.zip/ansible/modules/command.py", line 361, in main
module.fail_json(**r)
Message: The command exited with a non-zero return code.
The above target exception was the direct cause of the following controller exception:
Traceback (most recent call last):
File "/opt/ansible/venv/lib/python3.14/site-packages/ansible/executor/task_executor.py", line 324, in _execute
utr.maybe_raise_on_result()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/opt/ansible/venv/lib/python3.14/site-packages/ansible/_internal/_task.py", line 1263, in maybe_raise_on_result
raise _captured.AnsibleResultCapturedError(self.exception.event, self)
ansible._internal._errors._captured.AnsibleResultCapturedError: Module failed: The command exited with a non-zero return code.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/ansible/venv/lib/python3.14/site-packages/ansible/executor/task_executor.py", line 327, in _execute
raise AnsibleTaskError(obj=self._task.get_ds()) from ex
ansible.errors.AnsibleTaskError: Task failed: Module failed: The command exited with a non-zero return code.
fatal: [test.example.com]: FAILED! =>
changed: true
cmd: |-
echo "``` | quote "
delta: '0:00:00.003953'
end: '2026-08-04 18:32:32.684389'
msg: The command exited with a non-zero return code.
rc: 2
start: '2026-08-04 18:32:32.680436'
stderr: '/bin/bash: -c: line 1: unexpected EOF while looking for matching ``'''
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
Is there a way to workaround that issue?