Ansible templates and urlencode

If you use ansible templates to generate your config, and strong passwords, chances are that you know to use urlencode:

{
    "postgres": "postgres://{{ db_user }}:{{ db_password|urlencode() }}@{{ db_server }}/{{ db_name }}",
}

to ensure that any special chars are not mangled. Unfortunately, as I discovered to my cost, the jinja filter does NOT encode a forward slash as %2F.

3 thoughts on “Ansible templates and urlencode

  1. Susmita Gangopadhyay's avatar Susmita Gangopadhyay February 16, 2023 / 5:55 pm

    Thank you for sharing this. Helped me to save few hours today !

Leave a reply to nelsnelson Cancel reply