How to convert a csv file

18 views
Skip to first unread message

Takeshi Kuramochi

unread,
Nov 1, 2016, 6:14:53 AM11/1/16
to ansible...@googlegroups.com

Hi Everyone,

I have created a playbook which reads a csv file and converts it into variables then executes the task. My playbook is actually fine  -- and gives me what I expect to see, but I want to make my csv file format into simpler –something like this:

"command","savefile"
"command","savefile"
"command","savefile"
"command","savefile"

 

My current csv file is like this:

-------------------

"ls -l /etc","ls_l"

"hostid","hostid_out"

"cat /etc/hosts","cat_hosts"

-------------------

 

Is there any better way to make my csv file simpler? Any thoughts?

 

My playbook is:

vars:

    inputfile1: "./sample.csv"

 

  tasks:

    - debug: msg="Col1 = {{ col1 }} , Col2 = {{ col2 }}"

      vars:

        col1: "{{ lookup('csvfile', '{{ item }} file={{ inputfile1 }}

delimiter=, col=1') }}"

        col2: "{{ lookup('csvfile', '{{ item }} file={{ inputfile1 }}

delimiter=, col=2') }}"

      with_lines:

        - awk -F, '{ print $1 }' "{{ inputfile1 }}"

 

< sample1.csv >

-------------------

1,"ls -l /etc","ls_l"

2,"hostid","hostid_out"

3,"cat /etc/hosts","cat_hosts"

-------------------

Reply all
Reply to author
Forward
0 new messages