apigee / henchman

Orchestration and Automation tool
BSD 2-Clause "Simplified" License
109 stars 19 forks source link

using templates as lists in with_items #118

Closed jlin21 closed 8 years ago

jlin21 commented 8 years ago
name: "With Items test"
hosts:
  - individual
debug: true
vars:
  obj_array:
    - { name: 'objOne', value: 'oOne' }
    - { name: 'objTwo', value: 'oTwo' }
    - { name: 'objThree', value: 'oThree' }
tasks:
  - name: "Task {{ item }}"
    shell: cmd="echo {{ item }}"
    with_items: "{{vars.obj_array}}"

Using with_items with an "object array" won't work properly. Pongo2's template engine evaluates values into strings. In this case it would return "<[]interface{} Value>". For a standard string array, the henchman code can manually append |join:"," and then do a strings.split(...). For this issue, it may require doing a recursive loop and storing every value into a map before moving forward.