Q:

Ansible playbook with json output

I'm new to ansible and I'm having a problem passing a variable into json_query to read elements from a json array. 
working line:
Interface:{{ result.json | json_query('[2]')}}"

I would like to replace number 2 for a variable that will change. 
I tried:
- name: Interfaces
  debug:
    msg:
    - Interface:{{ result.json | json_query('[ item ]')}}"
  with_sequence: start=2 end=5

but it failed. 
Thanks in advance! 

A:

I believe you were very close, but what you really want is:
- debug:
    msg:
    - Interface: "{{ result.json | json_query('[' + item + ']') }}"
  with_sequence: count=3

You were correct that inside the jinja2 mustaches item is a variable, but python does not auto-concatenate things, so you must expressly ask for "[" and item to be joined together

