Re: [ansible-project] correct csv format

28 views
Skip to first unread message
Message has been deleted

Karl Auer

unread,
Aug 24, 2020, 5:23:06 AM8/24/20
to ansible-project
Hullo Monica

I'm not sure, but I seem to remember there is a CSV filter of some sort in Ansible, you could try looking for that.

Without knowing the format of the input you are using, it's hard to advise, but one option might be to output the columns into three separate files (without commas), and using the paste utility to paste them together.

Can you provide some sample input? Also, what does PFB mean?

Regards, K.
On Mon, Aug 24, 2020 at 6:11 PM Monica D <dmoni...@gmail.com> wrote:
Hi All,

I am facing issue while storing the output to a csv file using a shell module.
PFB my script written-:
  - name: list output to CSV
    shell: echo "{{ item  }}" >> file_output.csv
    delegate_to: 127.0.0.1
    with_items: "{{ output }}"

the output of csv file-:

server1
server2
server3
PermitEmptyPasswords no
PermitEmptyPasswords no
PermitEmptyPasswords no
Found
Not Found
Not Found 
 
But I want output in this format-:

server1, PermitEmptyPasswords no , Found 
server2, PermitEmptyPasswords no , Not Found   
server3, PermitEmptyPasswords no , Not  Found   

--
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/311645d5-6642-4445-b434-9a9a0e6689bbn%40googlegroups.com.


--

Karl Auer { manager, systems support }
P: 1300 759 975
E: ka...@2pisoftware.com
2pisoftware.com

GPG/PGP : DF6A 43E5 FB9D D884 C6CA CD7F 5278 212D E80F C107
Previous: 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E

Vladimir Botka

unread,
Aug 24, 2020, 6:27:33 AM8/24/20
to Monica D, ansible...@googlegroups.com
On Mon, 24 Aug 2020 01:10:57 -0700 (PDT)
Monica D <dmoni...@gmail.com> wrote:

> server1
> server2
> server3
> PermitEmptyPasswords no
> PermitEmptyPasswords no
> PermitEmptyPasswords no
> Found
> Not Found
> Not Found
>
> *But I want output in this format-:*
>
> server1, PermitEmptyPasswords no , Found
> server2, PermitEmptyPasswords no , Not Found
> server3, PermitEmptyPasswords no , Not Found

Try this

- shell: echo
"{{ lines|map('extract', output)|list|join(',') }}"
>> file_output.csv
loop: "{{ range(0, len|int)|list }}"
vars:
step: 3
len: "{{ output|length / step }}"
lines: "{{ range(item, output|length, step)|list }}"

--
Vladimir Botka

Vladimir Botka

unread,
Aug 24, 2020, 7:01:49 AM8/24/20
to Monica D, Ansible Project
On Mon, 24 Aug 2020 16:08:10 +0530
> Thank you so much for your reply.
> The condition provided by you is giving below output-:
>
> server1
> server2
> server 3
>
> But I want output in this format-:
> server1, PermitEmptyPasswords no , Found
> server2, PermitEmptyPasswords no , Not Found
> server3, PermitEmptyPasswords no , Not Found

This is probably the right time you post the "output".

You've already said

- name: list output to CSV
shell: echo "{{ item }}" >> file_output.csv
delegate_to: 127.0.0.1
with_items: "{{ output }}"

*the output of csv file-:*

server1
server2
server3
PermitEmptyPasswords no
PermitEmptyPasswords no
PermitEmptyPasswords no
Found
Not Found
Not Found

I guessed the variable "output" is a list

output:
- server1
- server2
- server3
- PermitEmptyPasswords no
- PermitEmptyPasswords no
- PermitEmptyPasswords no
- Found
- Not Found
- Not Found

Is it?

--
Vladimir Botka
Reply all
Reply to author
Forward
0 new messages