Ansible is built with Python, and many things in there relate to the way Python works. String replacement, however, is slightly different. Trying to run the following playbook:
---
- tasks:
- debug:
msg: "{{ string.replace('something', 'some', 'any') }}"
will result in Ansible complaining about an undefined variable string
being used.
Ansible Playbooks use the [Jinja2][jinja2] template engine, which provides a way to achieve this with a replace
filter.
Running the following playbook:
---
- tasks:
- debug:
msg: "{{ 'something' | replace('some', 'any') }}"
will successfully print out the debug message with anything
.