0

I have been trying to write a role which has a variable that initiated to null and values are appended based on the Jinja filters applied on the items, But it frequently errors out in

{
  "msg": "template error while templating string: expected token 'name', got 'string'. String: {{\n append\n  | default([])\n  | \"{{ statement }}\"\n}}"
}

testplaybook.yml:

- name: Processing role
  include_role:
    name: processing
  vars:
    statement: "combine({item._ansible_item_label.1:item.status|default('no status')})"

processing\tasks\main.yml:

- name: Matching items to values
  set_fact:
   append: >-
     {{ 'append | default([]) |' + statement }}
  loop: "{{ results }}"
  register: append

Expected result is that "append" should be able to populate based on the filters applied to the items in the "statement" variable just like it will be to do in a single page playbook.

TR007
  • 47
  • 1
  • 8
  • `{{ append | default([]) + statement }}` -- this should be like this – error404 Jun 07 '19 at 06:55
  • Hello, Thanks for the response. But it did not work. Same error thrown. – TR007 Jun 07 '19 at 07:12
  • https://stackoverflow.com/questions/55437561/ansibleerror-template-error-while-templating-string-expected-token-end-of-sta – error404 Jun 07 '19 at 07:33
  • You have an indentation problem. I would work on that first. – AHT Jun 07 '19 at 11:47
  • Hello AHT, this might be an copy paste error as such indentation issues will be caught by my editor. I have corrected in the question. – TR007 Jun 07 '19 at 15:45
  • I have tried this with lookup {{ lookup('vars', 'append | default([]) | ' + statement) }} but it did not work out – TR007 Jun 07 '19 at 16:30

0 Answers0