Envsubst is a useful tool that saves you from writing complex and brittle sed
s
export LOGSTASH_HOST="logstash.example.com:5044"
export CACHE_LOGS_DIRECTORY="/var/lancache/logs"
name: "lancache"
filebeat.prospectors:
- type: log
paths:
- ${CACHE_LOGS_DIRECTORY}/*.log
output.logstash:
hosts: ["${LOGSTASH_HOST}"]
#!/bin/bash
source .env
# envsubst only substitutes the vars passed to it in single quotes
# any other text starting with a dollar sign in the file will not be changed
envsubst '$LOGSTASH_HOST $CACHE_LOGS_DIRECTORY' < "filebeat.yml.templ" > "/etc/filebeat/filebeat.yml"
name: "lancache"
filebeat.prospectors:
- type: log
paths:
- /var/lancache/logs/*.log
output.logstash:
hosts: ["/var/lancache/logs"]
How easy is that!