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

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:

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 }} ; " }