Create file who is in my csv file

29 views
Skip to first unread message

Karther

unread,
Jan 13, 2020, 11:10:14 AM1/13/20
to Ansible Project
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


Vladimir Botka

unread,
Jan 13, 2020, 11:35:07 AM1/13/20
to Karther, ansible...@googlegroups.com
On Mon, 13 Jan 2020 08:10:14 -0800 (PST)
Karther <ryadmo...@gmail.com> wrote:

> filename,state,note,temps
> file1,0,my fisrt note,52
> file2,0,my second note,34
> file3,0,my thirst note,71
>
> ... my goal is that create all file sucessively (file1, file2,
> file3, ...)

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

For example

- hosts: localhost
tasks:
- read_csv:
path: csv_file.csv
register: my_files
- debug:
var: my_files.list

gives

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

The loop the list and create files. For example

- copy:
dest: "{{ item.filename }}"
content: "{{ item.note }}"
loop: "{{ my_files.list }}"

HTH,

-vlado

Karther

unread,
Jan 14, 2020, 8:00:35 AM1/14/20
to Ansible Project
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

Vladimir Botka

unread,
Jan 14, 2020, 8:12:28 AM1/14/20
to Karther, ansible...@googlegroups.com
On Tue, 14 Jan 2020 05:00:35 -0800 (PST)
Karther <ryadmo...@gmail.com> wrote:

> My problem is that there is problem of syntax with module read_csv:
>
> *- 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*

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

Karther

unread,
Jan 14, 2020, 9:07:11 AM1/14/20
to Ansible Project
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

Karther

unread,
Jan 14, 2020, 9:30:35 AM1/14/20
to Ansible Project
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

Dick Visser

unread,
Jan 14, 2020, 9:33:03 AM1/14/20
to ansible...@googlegroups.com
Ansible too old?
read_csv is available from 2.8
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4e41628c-9acf-41cb-a283-aac57832d976%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Karther

unread,
Jan 14, 2020, 9:57:06 AM1/14/20
to Ansible Project
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
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

Vladimir Botka

unread,
Jan 14, 2020, 11:14:58 AM1/14/20
to Karther, ansible...@googlegroups.com
On Tue, 14 Jan 2020 06:57:06 -0800 (PST)
Karther <ryadmo...@gmail.com> wrote:

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

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
Reply all
Reply to author
Forward
0 new messages