# Create file who is in my csv file

**URL:** <https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957>\
**Category:** Ansible Project\
**Created:** [January 13, 2020, 4:10pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957 "2020-01-13T16:10:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [January 13, 2020, 4:10pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/1 "2020-01-13T16:10:14Z")

</div>

Hey all !! 🙂

I have csv file with this content :

filename,state,note,temps  
file1,0,my fisrt note,52  
file2,0,my second note,34

file3,0,my thirst note,71

i have this task :

- set\_fact:  
csvfile: “{{ lookup(‘csvfile’, ‘file=/home/ansible/mssql\_query/roles/files/csv\_file.csv delimiter=,’) }}”

but not works, my goal is that create all file sucessively (file1, file2, file3, …) in some repertory

Someone have any idea please ?

Thanks very much community ansible !! 😉

Regards,

Karther

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 13, 2020, 4:34pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/2 "2020-01-13T16:34:53Z")

</div>

You might be better off with the 'read\_csv' module  
[https://docs.ansible.com/ansible/latest/modules/read\_csv\_module.html#read-csv-read-a-csv-file](https://docs.ansible.com/ansible/latest/modules/read_csv_module.html#read-csv-read-a-csv-file)

For example

&nbsp;&nbsp;&nbsp;&nbsp;- hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- read\_csv:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: csv\_file.csv  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: my\_files  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: my\_files.list

gives

&nbsp;&nbsp;&nbsp;&nbsp;"my\_files.list": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"filename": "file1",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"note": "my fisrt note",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"state": "0",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"temps": "52"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"filename": "file2",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"note": "my second note",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"state": "0",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"temps": "34"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"filename": "file3",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"note": "my thirst note",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"state": "0",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"temps": "71"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;]

The loop the list and create files. For example

&nbsp;&nbsp;&nbsp;&nbsp;- copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "{{ item.filename }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: "{{ item.note }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ my\_files.list }}"

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [January 14, 2020, 1:00pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/3 "2020-01-14T13:00:35Z")

</div>

Hey Vladimir !! 🙂

Thanks for your answer,

My problem is that there is problem of syntax with module read\_csv:

My task is :

**- name: “Read users from CSV file and return a list”**  
**read\_csv:**  
**path: /home/ansible/mssql\_query/roles/files/csv\_file.csv**  
**delimiter: ‘,’**  
**register: file\_csv**  
**delegate\_to: localhost**

Best Regards,

Karther

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 14, 2020, 1:12pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/4 "2020-01-14T13:12:14Z")

</div>

The syntax seems to be OK. Could you disclose the details of the error  
message?

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [January 14, 2020, 2:07pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/5 "2020-01-14T14:07:11Z")

</div>

Hey Vladimir,

The error is :

**ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.**

**The error appears to have been in ‘/home/ansible/mssql\_query/roles/tasks/main.yml’: line 36, column 3, but may**  
**be elsewhere in the file depending on the exact syntax problem.**

**The offending line appears to be:**

**- name: “Read users from CSV file and return a list”**  
**^ here**

Thanks for your help !! 🙂

Best regards,

Karther

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [January 14, 2020, 2:30pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/6 "2020-01-14T14:30:35Z")

</div>

And,

I have this problem only with module read\_csv it’s very strange …  
all parameters are well indented

Can you help me please …

Best regards,

Karther

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 14, 2020, 2:32pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/7 "2020-01-14T14:32:36Z")

</div>

Ansible too old?  
read\_csv is available from 2.8

---

<div class="post-metadata">

**Author:** ![Karther](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@Karther](https://forum.ansible.com/u/Karther)\
**Post date:** [January 14, 2020, 2:57pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/8 "2020-01-14T14:57:06Z")

</div>

Hello Visser,

My version is :

**ansible 2.8.0.dev0**  
**config file = /etc/ansible/ansible.cfg**  
**configured module search path = [u’/usr/share/ansible’]**  
**ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible**  
**executable location = /var/ansible/bin/ansible**  
**python version = 2.7.9 (default, Sep 14 2019, 20:00:08) [GCC 4.9.2]**

Maybe 2.8.0.dev0 is not good version ? It’s not same that version 2.8.0 ?

Thanks for your answers !! 🙂

Best regards,

Karther

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 14, 2020, 4:14pm UTC](https://forum.ansible.com/t/create-file-who-is-in-my-csv-file/31957/9 "2020-01-14T16:14:43Z")

</div>

This looks suspicious. Upgrade to the latest stable version in your distro.  
Probably 2.9.0 ? See "Release and maintenance"  
[https://docs.ansible.com/ansible/latest/reference\_appendices/release\_and\_maintenance.html](https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html)
