# Variable value saving into one column of csv file

**URL:** <https://forum.ansible.com/t/variable-value-saving-into-one-column-of-csv-file/31474>\
**Category:** Ansible Project\
**Created:** [October 16, 2019, 9:27am UTC](https://forum.ansible.com/t/variable-value-saving-into-one-column-of-csv-file/31474 "2019-10-16T09:27:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhay\_srivastava](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@abhay\_srivastava](https://forum.ansible.com/u/abhay_srivastava)\
**Post date:** [October 16, 2019, 9:27am UTC](https://forum.ansible.com/t/variable-value-saving-into-one-column-of-csv-file/31474/1 "2019-10-16T09:27:35Z")

</div>

Hi,

I want to save 1st variable value coming from loop into 1st column and 2nd variable value coming from loop into 2nd column and so on.

- local\_action: lineinfile line=“{{ result.results[item|int].container.Config.Hostname }}” dest=/tmp/abhay.csv

with\_sequence: start=0 end=“{{ count|int }}”

- local\_action: lineinfile line=“{{ result.results[item|int].container.State.Status }}” dest=/tmp/abhay.csv

with\_sequence: start=0 end=“{{ count|int }}”

Result should be like below

var1.value1 var2.value1  
var1.value2 var2.value2  
var1.value3 var2.value3

How to achieve this.

---

<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:** [October 16, 2019, 11:08am UTC](https://forum.ansible.com/t/variable-value-saving-into-one-column-of-csv-file/31474/2 "2019-10-16T11:08:00Z")

</div>

> Hi,
> 
> I want to save 1st variable value coming from loop into 1st column and 2nd variable value coming from loop into 2nd  
> column and so on.
> 
> - local\_action: lineinfile line="{{ result.results[item|int].container.Config.Hostname }}" dest=/tmp/abhay.csv  
> with\_sequence: start=0 end="{{ count|int }}"
> 
> - local\_action: lineinfile line="{{ result.results[item|int].container.State.Status }}" dest=/tmp/abhay.csv  
> with\_sequence: start=0 end="{{ count|int }}"
> 
> Result should be like below
> 
> var1.value1 var2.value1  
> var1.value2 var2.value2  
> var1.value3 var2.value3
> 
> How to achieve this.

I would suggest to use a template instead of lineinfile.

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

---

<div class="post-metadata">

**Author:** ![abhay\_srivastava](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@abhay\_srivastava](https://forum.ansible.com/u/abhay_srivastava)\
**Post date:** [October 16, 2019, 11:37am UTC](https://forum.ansible.com/t/variable-value-saving-into-one-column-of-csv-file/31474/3 "2019-10-16T11:37:32Z")

</div>

Can you please provide me any example.
