# Appending multiple values to same cell in csv ansible

**URL:** <https://forum.ansible.com/t/appending-multiple-values-to-same-cell-in-csv-ansible/35782>\
**Category:** Ansible Project\
**Created:** [September 24, 2021, 1:40pm UTC](https://forum.ansible.com/t/appending-multiple-values-to-same-cell-in-csv-ansible/35782 "2021-09-24T13:40:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumaresan\_M](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@Kumaresan\_M](https://forum.ansible.com/u/Kumaresan_M)\
**Post date:** [September 24, 2021, 1:40pm UTC](https://forum.ansible.com/t/appending-multiple-values-to-same-cell-in-csv-ansible/35782/1 "2021-09-24T13:40:32Z")

</div>

Hi All,

I am trying to append multiple values in same cell csv but not getting through.Could someone help here?

**Current output:**

Hostname Disk Info  
testserver sdd: 1.00 Gbsde: 1.00 Gb

**Expected output:**

Hostname Disk Info  
testserver sdd: 1.00 Gb  
sde: 1.00 Gb

**Playbook:**

- set\_fact:  
my\_devices: “{{ ansible\_devices.keys()|select(‘match’, ‘^sd(.\*)$’)|list }}”

- name: show templating results  
set\_fact:  
disk\_size: “{{ lookup(‘template’, ‘template-test.j2’) }}”

- set\_fact:  
csv\_data: “{{ inventory\_hostname }}, {{ disk\_size }}”

- lineinfile:  
path: /tmp/disks\_info.csv  
insertafter: EOF  
line: “{{ csv\_data }}”  
create: yes  
state: present  
mode: 0777  
connection: local

**Template:**

{%- for dev in my\_devices -%}  
{{ dev }}: {{ ansible\_devices[dev].size }}  
{%- endfor -%}

regards  
Kumar

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [September 25, 2021, 10:19am UTC](https://forum.ansible.com/t/appending-multiple-values-to-same-cell-in-csv-ansible/35782/2 "2021-09-25T10:19:52Z")

</div>

> Hi All,
> 
> I am trying to append multiple values in same cell csv but not getting through.Could someone help here?ne

lineinfile is certainly not the best solution to create from scratch. Try to write a template with a nested  
for loop over servers and devices. That way it would be a single task.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
