# line-in-file . line update from a list of values

**URL:** <https://forum.ansible.com/t/line-in-file-line-update-from-a-list-of-values/34737>\
**Category:** Ansible Project\
**Created:** [March 8, 2021, 8:08am UTC](https://forum.ansible.com/t/line-in-file-line-update-from-a-list-of-values/34737 "2021-03-08T08:08:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudu.c](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dudu.c](https://forum.ansible.com/u/dudu.c)\
**Post date:** [March 8, 2021, 8:08am UTC](https://forum.ansible.com/t/line-in-file-line-update-from-a-list-of-values/34737/1 "2021-03-08T08:08:47Z")

</div>

Hi

I’m using lineinfile to include new value inside a file

**Original line**

Kafka-list= kafka1:9092;kafka2:9092;kafka3:9092

I need to replace the value with parameters that are managed inside a configuration – I need to include all server hostname that are under kafka\_server\_details section

The line format should be :;:; ……

The list can include 1 or more servers

**Configuration File :**

kafka\_server\_details:

- {ip: 1.1.1.1 , hostname: [kafka1.cluster1.com](http://kafka1.cluster1.com) }
- {ip: 1.1.1.2 , hostname: [kafka2.cluster1.com](http://kafka2.cluster1.com) }
- {ip: 1.1.1.3 , hostname: [kafka3.cluster1.com](http://kafka3.cluster1.com) }  
kafka\_port: 9092

**Playbook**

- name: Update flow.properties file  
lineinfile:  
path: /opt/flow.properties  
regexp: “{{ item.from }}”  
line: “{{ item.replace\_with }}”  
with\_items:
- { from: lab=, replace\_with: lab=1 }
- { from: Kafka-list=, replace\_with: "Kafka-list= {{ kafka\_server\_details.hostname }}:{{ kafka\_port }} ; {{ kafka\_server\_details.hostname }}:{{ kafka\_port }} ; {{ kafka\_server\_details.hostname }}:{{ kafka\_port }} ; " }
