# Get a value from a fact from type type

**URL:** <https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242>\
**Category:** Ansible Project\
**Created:** [February 15, 2020, 4:22pm UTC](https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242 "2020-02-15T16:22:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [February 15, 2020, 4:22pm UTC](https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242/1 "2020-02-15T16:22:34Z")

</div>

I have a fact hostUUid when I display it with the following debug command

`

- name: debug uuid  
debug:  
msg:
- “{{ hostUUid | type\_debug }}”
- “{{ hostUUid }}”  
`

I get the following result:

`ok: [localhost] => { "msg": ["list", "[{u'id': u'7261c5626862-abafe49d9bac'}]" ] }`

How can i get only the ‘7261c5626862-abafe49d9bac’ value.  
I want to use that value in a body for a api request.  
When I use this in the in the uri module as body

body: ‘{“environmentUuid”: “7261c5626862”,“hostUuid”: {{ hostUUid }}"}’

I get following body with debug mode

`"body": "{\"environmentUuid\": \"7261c5626862\",\"hostUuid\": {u'id': u'7261c5626862-abafe49d9bac'}\"}",`

but the hostUuid needs to be only the value  
How can i solve that {{ hostUUid.id }} does also not work

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 15, 2020, 4:26pm UTC](https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242/2 "2020-02-15T16:26:06Z")

</div>

> I have a fact hostUUid when I display it with the following debug command
> 
> \>  
> -name:debug uuid  
> debug:  
> msg:  
> -"{{ hostUUid | type\_debug }}"  
> -"{{ hostUUid }}"  
> \>
> 
> I get the following result:
> 
> \>  
> ok:[localhost]=\>{  
> "msg":[  
> "list",  
> "[{u'id': u'7261c5626862-abafe49d9bac'}]"  
> ]  
> }  
> \>
> 
> How can i get only the '7261c5626862-abafe49d9bac' value.

It is the first element of the list, so you need to use {{ hostUUid[0] }}.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [February 15, 2020, 5:44pm UTC](https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242/3 "2020-02-15T17:44:04Z")

</div>

I already tried {{ hostUUid[0] }} gives also not the result I want.  
that gives this in the debug:

`ok: [localhost] => { "msg": ["list", { "id": "7261c5626862-abafe49d9bac" }] }`

the body now look like this:

`"body": "{\"environmentUuid\": \"7261c5626862\",\"hostUuid\": {u'id': u'7261c5626862-abafe49d9bac'}\"}",`

but is must be

`"body": "{\"environmentUuid\": \"7261c5626862\",\"hostUuid\": \"7261c5626862-abafe49d9bac\'"}",`

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [February 15, 2020, 7:08pm UTC](https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242/4 "2020-02-15T19:08:14Z")

</div>

solved my issue.

{{ hostUUid[0] }}

is working. But I had to set:

body\_format: json

in my uri

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 15, 2020, 7:08pm UTC](https://forum.ansible.com/t/get-a-value-from-a-fact-from-type-type/32242/5 "2020-02-15T19:08:23Z")

</div>

> I already tried {{ hostUUid[0] }} gives also not the result I want.  
> that gives this in the debug:

It is indeed a dict within a list, so please try hostUUid[0].id

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
