# json how to register variable with item only when matches

**URL:** <https://forum.ansible.com/t/json-how-to-register-variable-with-item-only-when-matches/27977>\
**Category:** Ansible Project\
**Created:** [July 6, 2018, 8:14pm UTC](https://forum.ansible.com/t/json-how-to-register-variable-with-item-only-when-matches/27977 "2018-07-06T20:14:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konstantin\_R](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@Konstantin\_R](https://forum.ansible.com/u/Konstantin_R)\
**Post date:** [July 6, 2018, 8:14pm UTC](https://forum.ansible.com/t/json-how-to-register-variable-with-item-only-when-matches/27977/1 "2018-07-06T20:14:57Z")

</div>

Hello,  
I have next playbook:

- hosts: 127.0.0.1  
tasks:
- name: Load variables  
include\_vars:  
file: vars/vcenter.yaml  
name: vcenter
- name: Get information about cluster  
vmware\_cluster\_facts:  
datacenter: ‘DC03’  
hostname: [vcenter.example.com](http://vcenter.example.com)  
username: ‘{{ vcenter.user }}’  
password: ‘{{ vcenter.password }}’  
validate\_certs: no  
register: cluster\_facts
- name: “Display all cluster names”  
debug: var=item  
with\_items: “{{ cluster\_facts.clusters }}”  
when: item == “ENV3”  
register: cluster\_name
- name: Print cluster name  
shell: |  
echo “{{ cluster\_name }}” \>\> out.txt

out.txt contains {‘msg’: u’All items completed’, ‘changed’: False, ‘results’: bla-bla-bla }

Is there a way to register only found value of item? Not the debug output.

Thanks

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [July 6, 2018, 9:16pm UTC](https://forum.ansible.com/t/json-how-to-register-variable-with-item-only-when-matches/27977/2 "2018-07-06T21:16:08Z")

</div>

After you registered a variable, you can usually use one of the following

registered\_variable.results  
registered\_variable.changed

registered\_variable.stdout  
registered\_variable.stdout\_lines

The output varies depending on the module you are executing. You can usually find out the format by looking at the bottom of a module’s documentation page.

Or You can use -vvvv to see the output and pick one that has the content you want.

–Tony Chia

---

<div class="post-metadata">

**Author:** ![kumar2](https://avatars.discourse-cdn.com/v4/letter/k/f14d63/32.png) [@kumar2](https://forum.ansible.com/u/kumar2)\
**Post date:** [July 9, 2018, 7:19am UTC](https://forum.ansible.com/t/json-how-to-register-variable-with-item-only-when-matches/27977/3 "2018-07-09T07:19:57Z")

</div>

Hi Konstantin,

I create one playbook it will automatically create a configuration in PingFederate using API. I can’t pass a variable inside the JSON file. I will attach the code given below.

env.yml it’s my environment variable file.

---

<div class="post-metadata">

**Author:** ![kumar2](https://avatars.discourse-cdn.com/v4/letter/k/f14d63/32.png) [@kumar2](https://forum.ansible.com/u/kumar2)\
**Post date:** [July 9, 2018, 7:29am UTC](https://forum.ansible.com/t/json-how-to-register-variable-with-item-only-when-matches/27977/4 "2018-07-09T07:29:19Z")

</div>

Hi,

If I pass the environmental variable inside the JSON file. At that time, whatever I entered inside the double quotes it should be printed. I want to get the what I set it on the variable. my problem file is listed below. please help me. Thanks in advance.

{  
“name”: “userName”,  
“value”: “{{pingferderate.username}}”  
},

Output for value:

{{pingferderate.username}}

but I want the variable value set it on the environmental file

Jack

env.yml
