# Loop on  values and ssh

**URL:** <https://forum.ansible.com/t/loop-on-values-and-ssh/31518>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [October 22, 2019, 10:29pm UTC](https://forum.ansible.com/t/loop-on-values-and-ssh/31518 "2019-10-22T22:29:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boa\_Ah](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@Boa\_Ah](https://forum.ansible.com/u/Boa_Ah)\
**Post date:** [October 22, 2019, 10:29pm UTC](https://forum.ansible.com/t/loop-on-values-and-ssh/31518/1 "2019-10-22T22:29:02Z")

</div>

Team,

I have json response from which am getting query with hosts name. I need to further take all goats names and ssh and run some command.

How can I achieve this? Please give complete syntax.

@Rahul Rameshbabu may be you can catch this?

basically, i have below task that yields above output..

```-
        k8s_facts:
          kubeconfig: $WORKSPACE
          kind: Node
          label_selectors:
          - nodeType=gpu
          verify_ssl: no
        register: gpu_node_info

#Form a list of dic with key value
      - debug:
          var: gpu_node_info | json_query(query)
        vars:
          query: 'resources[].{node_name: metadata.name}'

```

Output:

rfr \*pulling dict value and ssh in loop to all the values\*

````auto
    "gpu_node_info | json_query(query)": [
        {
            "node_name": "host2"
        },
        {
            "node_name": "host1"
        }
    ]
}```

Below is my try to loop and ssh which fails
```- name: "Loop on all nodeNames and ssh."
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: ssh \-F \~/\.ssh/ssh\_config bouncer@\{\{ item \}\}\.internal\.sshproxy\.net &quot;name \-a&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: ssh\_result\_per\_host
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;failed\_when: ssh\_result\_per\_host\.rc \!= 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: &quot;\{\{ var\.node\_name \}\}&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\- debug:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: ssh\_result\_per\_host\.stdout\_lines\`\`\`
````
