ansible parse json with several keys with the same name to one list variable
<p>I have an issue to parse a json using ansible
I have a task that connected to rancher and get a json file</p>

<p>task:</p>

<pre><code>- uri:
    url: http://rancher.local:8080/v1/hosts
    method: GET
    user: ##################
    password: ################
    body_format: json
  register: hosts_json

- name: test
  set_fact:
    rancher_env_hosts: "{{ item.hostname }}"
  #when: item.hostname == "*-i-*"
  with_items: "{{hosts_json.json.data}}"

- name: output
  debug:
    msg: "hosts: {{rancher_env_hosts}}"
</code></pre>

<p>and I get the following json (after edit it to be more readable):</p>

<pre><code>{
    "json": {
        "data": [
            {
                "hostname": "rancher-i-host-02",
                "id": "adsfsa"
            },
            {
                "hostname": "rancher-i-host-01",
                "id": "gfdgfdg"
            },
            {
                "hostname": "rancher-q-host-01",
                "id": "dfgdg"
            },
            {
                "hostname": "rancher-q-host-02",
                "id": "dfgdg"
            }
        ]

    }

}
</code></pre>

<p>When I start the playbook I get only the last host name in the variable and not all the list of hostname. can I register all the list to the same variable?</p>

<p>In addition, I also added a line with the a comment "#" in order to get only the host names that match the string "-i-" bit it's not working. any idea?</p>