2

I have ansible tasks at hand that download stuff, but the urls are so long that I should probably create variables for each part of it. Is there another thing I can do to fit the url in my preferred line length, like a multiline value for the 'url' key? How would I do that?

I have seen a similar problem with multiline strings but the solutions don't seem to be for urls.

Examples of my tasks:

- name: Download stuff
  get_url:
    url: https://some.very.looooooooong/url/wowThisUrlIssoooLong/IcantbelieveWhyThiswouldExistInTheRealWorld/butItdoes/apparently
    dest: /tmp/myFilename.bar
    remote_src: yes
    delegate_to: localhost

- name: Download more stuff
  get_url:
    url: "{{ item.url }}"
    dest: "/tmp/{{ item.name }}"
    remote_src: yes
  delegate_to: localhost
  with_items:
  - { url: "https://some.very.looooooooong/url/wowThisUrlIssoooLong/IcantbelieveWhyThiswouldExistInTheRealWorld/butItdoes/apparently", name:"myFilename.bar" }
  • Using Ansible 2.10
Human
  • 726
  • 8
  • 27

1 Answers1

3

The double-quoted solution that's part of the solution you linked does work:

- name: Download stuff
  get_url:
    url:
      "https://some.very.looooooooong/url/\
       wowThisUrlIssoooLong/IcantbelieveWhyThiswouldExistInTheRealWorld/\
       butItdoes/apparently"
    dest: /tmp/myFilename.bar
    remote_src: yes
    delegate_to: localhost

- name: Download more stuff
  get_url:
    url: "{{ item.url }}"
    dest: "/tmp/{{ item.name }}"
    remote_src: yes
  delegate_to: localhost
  with_items:
  - { url: "https://some.very.looooooooong/url/wowThisUrlIssoooLong\
            /IcantbelieveWhyThiswouldExistInTheRealWorld/butItdoes/apparently",
      name: "myFilename.bar" }

YAML double quoted scalars are the only scalars that can break at any character by using an escaped line break.

flyx
  • 35,506
  • 7
  • 89
  • 126