Allgemein

Problem with wrapping URLs in the Ansible get_url Module

Ansible: Wrap long URLs in the get_url Module

If there is the Situation that your ansible playbooks need to pass a Linder, but you have very long URLs to query, you will find that the >- or |- Operator won’t help to wrap the url into multiple lines because it will just lead to white spaces

ansible.builtin.uri:
  url: >-
       https://bastian-kuhn,com
       /wp-content/uploads/2025/
       11/17630480180408.jpg"
	fatal: [157.90.25.75 -> localhost]: FAILED! => {"changed": false, "elapsed": 0, "msg": "Status code was -1 and not [200]: An unknown error occurred: URL can't contain control characters. 'bastian-kuhn.com ' (found at least ' ')", "redirected": false, "status": -1, "url": "https://bastian-kuhn.com /wp-content/uploads/2025/ 11/17630480180408.jpg"}

The Solution is simple:

Make it a string and wrap this string:

ansible.builtin.uri:
  url: "https://bastian-kuhn.com\
        /wp-content/uploads/2025/\
        11/17630480180408.jpg"

Note here the Ticks at the beginning and the end, and the Backslash behind every line