# Feature request: CSV editor/updater, faster alternative to lineinfile

**URL:** <https://forum.ansible.com/t/feature-request-csv-editor-updater-faster-alternative-to-lineinfile/44547>\
**Category:** Get Help\
**Created:** [September 24, 2025, 8:53am UTC](https://forum.ansible.com/t/feature-request-csv-editor-updater-faster-alternative-to-lineinfile/44547 "2025-09-24T08:53:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![calimero444](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/calimero444/32/9266_2.png) [@calimero444](https://forum.ansible.com/u/calimero444)\
**Post date:** [September 24, 2025, 8:53am UTC](https://forum.ansible.com/t/feature-request-csv-editor-updater-faster-alternative-to-lineinfile/44547/1 "2025-09-24T08:53:08Z")

</div>

Hello,

Is there a faster alternative to update lines in a CSV file other than using lineinfile, which is too slow.  
I have one large CSV files with MAC addresses. I have an ansible job that runs across multiple inventories and switches. It needs to lookup the MAC address in the CSV and then update some fields of that line. lineinfile can do that, but it is horribly slow.  
The only alternative that i see is reading in the CSV in a variable and then change in memory and in the end write out the CSV to file, however, this is memory consuming.

Are there other ways ?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 24, 2025, 9:07am UTC](https://forum.ansible.com/t/feature-request-csv-editor-updater-faster-alternative-to-lineinfile/44547/2 "2025-09-24T09:07:08Z")

</div>

FWIW, use a database. For [example](https://docs.ansible.com/ansible/2.9/modules/postgresql_query_module.html#postgresql-query-module).

---

<div class="post-metadata">

**Author:** ![calimero444](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/calimero444/32/9266_2.png) [@calimero444](https://forum.ansible.com/u/calimero444)\
**Post date:** [September 24, 2025, 8:44pm UTC](https://forum.ansible.com/t/feature-request-csv-editor-updater-faster-alternative-to-lineinfile/44547/3 "2025-09-24T20:44:45Z")

</div>

yes a DB is a possibility.  
However,i think i have solved it in another way. I copy the existing CSV to old and create a new CSV during the playbook run. the new CSV is fast created by using a jinja template.  
I then “merge” both CSV together using pandas in a python script from Ansible where i give “priority” to the last created CSV.

# Combine them, giving priority to b (second CSV)

# b rows will overwrite a rows where keys are duplicated

combined\_df = pd.concat([a[~a.index.isin(b.index)], b])

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 25, 2025, 12:05am UTC](https://forum.ansible.com/t/feature-request-csv-editor-updater-faster-alternative-to-lineinfile/44547/4 "2025-09-25T00:05:40Z")

</div>

> [@calimero444](#):
>
> Combine them, giving priority to b

You don’t need pandas. For example, given the file `a.csv`

```auto
k1,foo
k2,bar
k3,baz

```

You can read it

```yaml
    a: "{{ lookup('file', 'a.csv') |
           community.general.from_csv(dialect='unix', fieldnames=['key', 'value']) |
           items2dict }}"

```

gives

```yaml
    a:
        k1: foo
        k2: bar
        k3: baz

```

To update duplicated keys from `b`

```yaml
    b:
        k2: new

```

combine the dictionaries

```yaml
    r: "{{ [a, b] | combine }}"

```

gives

```yaml
    r:
        k1: foo
        k2: new
        k3: baz

```

Rewrite the file `a.csv`

```yaml
    - copy:
        dest: a.csv
        content: |
          {% for k,v in r.items() %}
          {{ k }},{{ v }}
          {% endfor %}

```
