trying to loop with a list to create a append a yaml file; getting some syntactical error ?
any idea how we can fix this ?
- name: "append yml"
shell: echo "instances:
- name: all
- command: all
- arguments:
- cluster_name: mongo{{ item }} all
- host: {{ipv4}}
" >> /etc/newrelic-infra/integrations.d/postgresql-config.yml
shell: echo " - auth_source: admin
- ssl: false
- ssl_insecure_skip_verify: false
- labels:
- env: env
" >> /tmp/newrelic-infra/integrations.d/postgresql-config.yml
with_items: "{{ instances.stdout_lines }}"
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/ansible/projects/newrelic/mongo_nr.yml': line 27, column 47, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: "update yml"
shell: echo "instances:
- name: all
- command: all
- arguments:
- cluster_name: mongo{{ item }} all
- host: {{ipv4}}
" >> /etc/newrelic-infra/integrations.d/postgresql-config.yml
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
question from:
https://stackoverflow.com/questions/65923957/yaml-syntactical-error-with-items-loop-with-a-list 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…