# how to get value from yaml file ?

**URL:** <https://forum.ansible.com/t/how-to-get-value-from-yaml-file/29097>\
**Category:** Ansible Project\
**Created:** [November 22, 2018, 1:08pm UTC](https://forum.ansible.com/t/how-to-get-value-from-yaml-file/29097 "2018-11-22T13:08:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Chang](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@Eric\_Chang](https://forum.ansible.com/u/Eric_Chang)\
**Post date:** [November 22, 2018, 1:08pm UTC](https://forum.ansible.com/t/how-to-get-value-from-yaml-file/29097/1 "2018-11-22T13:08:00Z")

</div>

I want to run a playbook to create an individual folder for users in different groups

and I already create a teams.yml file like below

> > {
> 
> > “chinese\_name”: “\u8ca1\u52d9\u6703\u8a08\u8655”,
> 
> > “description”: “\u8ca1\u52d9\u6703\u8a08\u8655”,
> 
> > “gid”: 10126,
> 
> > “location”: [
> 
> > “hq”
> 
> > ],
> 
> > “name”: “ac”,
> 
> > “users”: [
> 
> > “tsengyi”,
> 
> > “chenp”,
> 
> > “lich”,
> 
> > “hsiaoch”,
> 
> > “wangr”,
> 
> > “dengm”,
> 
> > "“guot”.

> > ]

then I wrote a task

> ### load yaml file first

> - name: load teams.yml

> tags:

> - env

> include\_vars:

> file: files/konwen/teams.yml

> - name: create folders

> file:

> path: “/home/{{item.user}}/D”

> state: present

> when: item.name == ‘ac’

> with\_items: “{{ teams}}”

> 

but the result

> > tsengyi
> 
> > ‘[u’'‘tsengyi’'‘, u’'‘chenp’'‘, u’'‘lich’'‘, u’'‘hsiaoch’'‘, u’'‘wangr’'‘, u’'‘dengm’'‘, u’'‘guot’'‘, u’'‘hsul’'‘, u’'‘linm’'‘]’
> 
> > wangc

looks like ansible take whole list into a single value

I expect to create /home/tsengyi/D , /home/chenp/D …and so on

How can I separate the list into piece to do what I need ??

---

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [November 22, 2018, 7:28pm UTC](https://forum.ansible.com/t/how-to-get-value-from-yaml-file/29097/2 "2018-11-22T19:28:08Z")

</div>

Hi,

your file looks like JSON to me, not like YAML (though one is a subset of the other, if I remember correctly…).

My test:

### teams.yaml ###

---

<div class="post-metadata">

**Author:** ![Eric\_Chang](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@Eric\_Chang](https://forum.ansible.com/u/Eric_Chang)\
**Post date:** [November 23, 2018, 5:37am UTC](https://forum.ansible.com/t/how-to-get-value-from-yaml-file/29097/3 "2018-11-23T05:37:33Z")

</div>

thanks for reply , I think my source file is yaml file

I can pass the yaml validator online

here are 2 items in teams.yml

> “teams”: [  
> {“chinese\_name”: “\u79d8\u66f8\u90e8”,“description”: “\u79d8\u66f8\u90e8”,“gid”: 10125,“location”: [“hq”],“name”: “aa”,“users”: [“chenhu”,“chouf”]},  
> {“chinese\_name”: “\u8ca1\u52d9\u6703\u8a08\u8655”,“description”: “\u8ca1\u52d9\u6703\u8a08\u8655”,“gid”: 10126,“location”: [“hq”],“name”: “ac”,“users”: [“chenchiao”,“chengc”]}  
> ]

even I assign a name in task , I still can not use users with tasks below

> - name: load teams.yml  
> tags:
> 
> - env  
> include\_vars:  
> file: files/teams.yml  
> name: teams
> 
> - name: debug  
> tags:
> 
> - env  
> debug:  
> msg: “{{ item }}”  
> loop: " {{ users }}"

I can print the {{ teams }} , but can not get valule from {{ team.users }} or {{ team.name }}  
FAILED! =\> {“msg”: "The task includes an option with an undefined variable. The error was: ‘name’ is undefined / The error was: ‘chinese\_name’ is undefined

Eric Chang於 2018年11月22日星期四 UTC+8下午9時08分01秒寫道：

---

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [November 23, 2018, 6:20am UTC](https://forum.ansible.com/t/how-to-get-value-from-yaml-file/29097/4 "2018-11-23T06:20:35Z")

</div>

What version of Ansible?

Are you sure the files are encoded in UTF-8?
