Search code examples
ansiblestatic-analysisansible-lint

Line too long: Ansible lint


This is my Ansible task

- name: no need to import it.
  ansible.builtin.uri:
    url: >
      https://{{ vertex_region }}-aiplatform.googleapis.com/v1/projects/{{ project }}/locations/{{ vertex_region }}/datasets/{{ dataset_id }}/dataItems
    method: GET
    headers:
      Content-Type: "application/json"
      Authorization: Bearer "{{ gcloud_auth }}"
  register: images

While checking for Ansible lint, it spills out:

line too long (151 > 120 characters) (line-length)

The error is for the url parameter of the task. I already used > to break down the url, not sure how I can reduce it even more to fit in line constrain given by Ansible lint?


Solution

  • If you want to obey the lint line length rule, you need to split your url on several lines.

    > is the yaml folded scalar block indicator: new lines will be replaced by spaces. This is not what you want.

    The best solution here is to use a double quoted flow scalar where you can escape new lines so that they are not converted to white spaces, e.g.:

        url: "https://{{ vertex_region }}-aiplatform.googleapis.com/v1/projects/\
             {{ project }}/locations/{{ vertex_region }}/datasets/{{ dataset_id }}/dataItems"
    

    You can add as many escaped new lines as you whish if this is still too long.

    https://yaml-multiline.info/ is a good ressource to learn all possibilities for multiline strings in yaml.