| 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 ************************************************************************************************************************************************************************************************************** |