json - how it I parse each row of data from the google sheets api with ansible's with_items? -


i using google sheets v4 values collection , having trouble figuring out how each row parse in {{ item }}

my ansible ymal looks like.

tasks: - name: debug url   debug:     msg: "{{ g_url }}" - name: data google spead sheet api   uri:     url: "{{ g_url }}"     return_content: yes     dest: /tmp/o_gd_form.json   register: google_data - name: whats dump?   debug:     var: "{{ item.0 |to_json }}"   with_items: "{{ google_data.json.values() }}" # line needs fixed 

and the responding json looks like:

{   "range": "sheet1!a1:d5",   "majordimension": "rows",   "values": [     ["item", "cost", "stocked", "ship date"],     ["wheel", "$20.50", "4", "3/1/2016"],     ["door", "$15", "2", "3/15/2016"],     ["engine", "$100", "1", "30/20/2016"],     ["totals", "$135.5", "7", "3/20/2016"]   ], } 

i can't seem figure out how write the with_items return {{ item }} of json ["engine", "$100", "1", "30/20/2016"].

any or need split task out middleware parser?

the google sheets api documentation at:

https://developers.google.com/sheets/samples/reading

to want, use:

    - debug: msg="name={{ item.0 }} cost={{ item.1 }}"       with_list: "{{ google_data.json['values'] }}" 

there 2 problems in code:

  1. values special keyword, can't access json.values, should use json['values'] instead.

  2. with_items flattens list of lists, end long list of strings. should use with_list iterate on outer list (rows) , inner lists (column values) items.


Comments