Consider the following Ansible task:
- name: "Install Python packages"
ansible.builtin.pip:
name:
- "foobar"
extra_args: "--no-index --find-links=file://{{ role_path }}/files/pip/"
This task installs a Python package from a pre-downloaded package file which is stored with the Ansible role.
However, there is a gotcha here: if the path on disk where the Ansible role is located contains whitespace or a backslash, the --find-links
argument will be parsed incorrectly.
What I need is some form of filter or function which will apply the equivalent of printf '%q'
to the {{ role_path }}
variable, escaping all whitespace or special characters. Is there such a function in Ansible or Jinja2?