3

I have a Ansible line that fails linting:

 tags: "{{ deployment_id | resource_tags('asg', base_resource_tags, deployment=deployment_id, deployment_env=deployment_env, deployment_name=deployment_name, purpose=deployment_purpose_tag, cpu_utilization=deployment_cpu_utilization_tag, disk_io_class=deployment_disk_io_tag, prom_exporters=deployment_prom_exporter_tags) | asg_tag_list }}"

How do I make this pass linting?

Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
  • Does this answer your question? [How do I break a string in YAML over multiple lines?](https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-in-yaml-over-multiple-lines) – stackprotector Mar 07 '23 at 12:24

1 Answers1

2

You need to use YAML Folding Scalars, > without quotes. Then add 'block chomping' 'strip'docs indicator to remove the trailing newline. The below example will work correctly, with each newline translating to a space. Adding quotes will break it e.g.

tags: >-
    {{ deployment_id | resource_tags('asg', base_resource_tags, deployment=deployment_id,
    deployment_env=deployment_env, deployment_name=deployment_name, Purpose=deployment_purpose_tag,
    cpu_utilization=deployment_cpu_utilization_tag, disk_io_class=deployment_disk_io_tag,
    prom_exporters=deployment_prom_exporter_tags) | asg_tag_list }}
Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
  • Including `-` after the fold operator (as in: `: >-`) will trim the trailing newline; your version is equivalent to `tags: "{{ ... }}\n"` which isn't what was in the original line – mdaniel Aug 26 '20 at 04:11
  • 1
    Related: How do I [break a string in YAML](https://stackoverflow.com/q/3790454/9624052) over multiple lines? – Andrew Richards Oct 13 '22 at 14:49