Since it is an URL and that the spaces should already be URL encoded, you could use a combination of YAML folded style — >
— with a clip block chomping indicator — -
— along with Jinja whitespace control — {{- ... -}}
.
All this together could be split in multiple line like:
- ansible.builtin.uri:
url: >-
https://
{{- vertex_region -}}
-aiplatform.googleapis.com/v1/projects/
{{- project -}}
/locations/
{{- vertex_region -}}
/datasets/
{{- dataset_id -}}
/dataItems
For long line that do not contains any Jinja statement or expression, see @Zeitounator's answer, or, use Jinja comment blocks along with whitespace control:
- ansible.builtin.uri:
url: >-
https://this_is_a_super_long_url_
{#- -#}
that_looks_like_it_cannot_be_split_
{#- -#}
into_multiples_lines_is_it_
{#- -#}
question_mark.example.com
Given the tasks:
- name: Demo debug with variable
ansible.builtin.debug:
msg: >-
https://
{{- vertex_region -}}
-aiplatform.googleapis.com/v1/projects/
{{- project -}}
/locations/
{{- vertex_region -}}
/datasets/
{{- dataset_id -}}
/dataItems
vars:
vertex_region: foo_region
dataset_id: bar_id
project: bar_project
- name: Demo debug without variable
ansible.builtin.debug:
msg: >-
https://this_is_a_super_long_url_
{#- -#}
that_looks_like_it_cannot_be_split_
{#- -#}
into_multiples_lines_is_it_
{#- -#}
question_mark.example.com
This gives:
TASK [Demo debug with variable] ******************************************************************
ok: [localhost] =>
msg: https://foo_region-aiplatform.googleapis.com/v1/projects/bar_project/locations/foo_region/datasets/bar_id/dataItems
TASK [Demo debug without variable] ***************************************************************
ok: [localhost] =>
msg: https://this_is_a_super_long_url_that_looks_like_it_cannot_be_split_into_multiples_lines_is_it_question_mark.example.com