json how to register variable with item only when matches

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
    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

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

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.

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