title: How to use environmental variables in Logstash 5.X?
body: <p>We've just switched from 2.X to 5.X, and I'm trying to find out how to use environmental variables in the pipeline configuration files.</p>
  
  <p>In 2.X, the following worked:</p>
  
  <pre><code>export HOSTNAME
  </code></pre>
  
  <p>Then start Logstash with the <code>--allow-env</code> command line flag. The pipeline configuration file looked like this:</p>
  
  <pre><code>filter {
         mutate {
                add_field =&gt; { "some_field" =&gt; "${HOSTNAME}"}
         }
  }
  </code></pre>
  
  <p>The documentation says that the <code>--allow-env</code> flag is not required anymore.</p>
  
  <p>I've tried to replace <code>mutate</code> with the <code>environment</code> filter, but with no luck.</p>
  
  <p>I've tried to edit the <code>startup.options</code> file. Added <code>HOSTNAME</code> as a usual environment variable, and added it between the <code>read-EOM</code> part, but without any positive results.</p>
  
  <p>What seems to be working now if I add the following part to the <code>/usr/share/logstash/bin/logstash.lib.sh</code> file, but I'm nut sure if I'm supposed to edit that.</p>
  
  <pre><code>HOSTNAME="the-name-of-the-host"
  export HOSTNAME
  </code></pre>
  
  <p>So my question is: what have I overlooked? What is the proper way to allow the usage of enviromental variables in Logstash's pipeline configuration files?</p>
  
  <p><strong>Note:</strong></p>
  
  <p>Like Alcanzar described, this works if I run Logstash manually. However we would like to run it with <code>systemctl</code>, so it should be automatically started by the daemon on startup. In 2.X, it worked fine with the <code>/etc/init.d/logstash</code> file, but as the <a href="https://www.elastic.co/guide/en/logstash/5.x/config-setting-files.html" rel="nofollow noreferrer">documentation</a> describes, that is no more. The files I'm supposed to edit are: <code>/etc/logstash/startup.options</code> and <code>/etc/logstash/logstash.yml</code>.</p>