On Sun, 12 Jan 2020 23:22:03 -0800 (PST)
Jegan A <[email protected]> wrote:

> ... I like to get value of "lifecycle_state" using 
> debug.
> 
>        - debug: var="{{ item }}"
>          with_items:  result_1.volume_attachments
> 
> ok: [localhost] => (item=result_1.volume_attachments) => {
>     "ansible_loop_var": "item",
>     "item": "result_1.volume_attachments",
>     "result_1.volume_attachments": [
>         {
>             "attachment_type": "iscsi",
>             "availability_domain": "xxxxxxxxx",
>             "chap_secret": null,
>             "chap_username": null,
>             "compartment_id": "xxxxxxxxxxx",
>             "device": null,
>             "display_name": "xxxxxxxxx",
>             "id": "xxxxxxxxxxx",
>             "instance_id": "xxxxxx",
>             "ipv4": "xxxxx",
>             "iqn": "xxxxxxxxxxxx",
>             "is_pv_encryption_in_transit_enabled": false,
>             "is_read_only": false,
>             "lifecycle_state": "ATTACHED",
>             "port": 3260,
>             "time_created": "xxxxxxxx",
>             "volume_id": "xxxxxxxxxxx"
>         }
>     ]
> }

The first 2 lines of the debug output explain what's going on

     "ansible_loop_var": "item",
     "item": "result_1.volume_attachments",

The list 'result_1.volume_attachments' is not expanded in the 'with_items'
statement and is submitted as 'item' to debug. Then the list is expanded
var="{{ item }}".

To print the 'lifecycle_state' attribute of the items in the list try

    - debug:
        var: item.lifecycle_state
      loop: "{{ result_1.volume_attachments }}"

Notes:
* Use 'loop' instead of with_*
  
https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.5.html#migrating-from-with-x-to-loop
* Expand the the variable "{{ result_1.volume_attachments }}" in the 'loop'
  to iterate the items of the list
  
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#using-variables-with-jinja2
* In 'debug' the parameter 'var' is expanded by default


HTH,
        -vlado

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200113091445.0d8435a9%40gmail.com.

Attachment: pgphVXnLvsJwq.pgp
Description: OpenPGP digital signature

Reply via email to