Eric_Chang  
                
                  
                    November 22, 2018,  1:08pm
                   
                  1 
               
             
            
              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 
 
 
tags:
 
 
include_vars:
 
file: files/konwen/teams.yml
 
 
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 ??
             
            
              
            
           
          
            
              
                Uwe_Sauter  
              
                  
                    November 22, 2018,  7:28pm
                   
                  2 
               
             
            
              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 ###
             
            
              
            
           
          
            
              
                Eric_Chang  
              
                  
                    November 23, 2018,  5:37am
                   
                  3 
               
             
            
              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”: [
 
even I assign a name in task , I still can not use users with tasks below
name: load teams.yml
 
env
 
name: debug
 
env
 
 
 
I can print the {{ teams }} , but can not get valule from {{ team.users }} or {{ team.name }}
Eric Chang於 2018年11月22日星期四 UTC+8下午9時08分01秒寫道:
             
            
              
            
           
          
            
              
                Uwe_Sauter  
              
                  
                    November 23, 2018,  6:20am
                   
                  4 
               
             
            
              What version of Ansible?
Are you sure the files are encoded in UTF-8?