Hi,

Trying to create files based on sourcefile, and of course when this 
construction works.. i will use it on lots of things. 
Version: ansible 2.4.2.0
I am trying to go through a source file ( in this case a list with users) 
and use every line i return in the file with the with_items loop to create 
files based on the each line.

As you can  see the return is "user1\nuser2\nuser3\nuser4"
i want to split the lines, so i can use the value/string of each individual 
line.
I am still fairly new with Ansible, so I am probably missing something 
fundamental.
What am i missing? Why can't i use stdout_lines on a lookup return?
"When stdout is returned, Ansible always provides a list of strings, each 
containing one item per line from the original output."

*$cat /etc/remote_users.txt* 
user1 
user2 
user3 
user4 

*$cat /opt/ansible/roles/testing/vars/main.yml* 
--- 
users: "{{ lookup('file', '/etc/remote_users.txt') }}" 

*$cat /opt/ansible/roles/testing/tasks/google.yml* 
--- 
- debug: msg="the value of source text is {{ users }}" 

- name: test files 
file: 
path: /home/thijn/{{ item }} 
state: touch 
mode: u=rw,g=r,o=r" 
with_items: "{{ users.stdout_lines }}" 
#with_items: "{{ users.stdout.split() }}" 
#with_items: "{{ users.stdout.split('/n') }}" 

*Expected to have the following files created:* 
/home/thijn/user1 
/home/thijn/user2 
/home/thijn/user3 
/home/thijn/user4 

*Actual output:* 
TASK [testing : debug] 
**************************************************************************************************************************************************************************************************
 
ok: [minion2] => { 
"msg": "the value of foo.txt is user1\nuser2\nuser3\nuser4" 
} 

TASK [testing : test files] 
*********************************************************************************************************************************************************************************************
 
fatal: [minion2]: FAILED! => {"failed": true, "msg": 
"'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
'stdout_lines'"} 

PLAY RECAP 
**************************************************************************************************************************************************************************************************************
 
minion2 : ok=2 changed=0 unreachable=0 failed=1 

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d64bfdf7-5868-4bea-b454-5fe8081c8a15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to