title: Ansible json_query - struggling with syntax
body: <p>I have read <a href="https://stackoverflow.com/questions/46048032/ansible-how-to-store-the-result-of-a-json-query">this question</a> and <a href="https://stackoverflow.com/questions/46541438/extracting-a-variable-from-json-output-then-debug-and-register-the-outout-with-a">this one</a> as well as the relevant <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#json-query-filter" rel="nofollow noreferrer">Ansible documentation</a>.</p>
  
  <p>I still can't work out what the correct syntax to use is.  I am trying the following:</p>
  
  <pre><code># Find all of the load-balancers reference
  - name: Gather facts about all load-balancers
    elb_application_lb_facts:
    register: load_balancers
  
  # Get the load-balancer we want
  - name: Find the correct load-balancer
    set_fact:
      load_balancer_dns: "{{ load_balancer_dns }}"
      elb_zone_id: "{{ elb_zone_id }}"
    with_items: "{{ load_balancers | json_query(lb_query) }}"
    vars:
      lb_query: "load_balancers[?load_balancer_name=='{{load_balancer_name}}'].{load_balancer_dns: dns_name, elb_zone_id: canonical_hosted_zone_id}"
  </code></pre>
  
  <p>This always results in the error (in the second task):  <code>The task includes an option with an undefined variable. The error was: 'load_balancer_dns' is undefined</code>.</p>
  
  <p>The JSON output from the <code>elb_application_lb_facts</code> does include the <code>dns_name</code> and <code>canonical_hosted_zone_id</code> keys and they are on the same level as <code>load_balancer_name</code> (not nested somewhere).</p>
  
  <p>Please could somebody help me with the syntax for this?</p>