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 }
- {ip: 1.1.1.2 , hostname: kafka2.cluster1.com }
- {ip: 1.1.1.3 , hostname: 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 }} ; " }