# ENvironmental variable hostname in logstash.yml and pipelines.yml or logstash.conf

**URL:** <https://discuss.elastic.co/t/environmental-variable-hostname-in-logstash-yml-and-pipelines-yml-or-logstash-conf/207508>\
**Category:** Logstash\
**Created:** [November 12, 2019, 12:25pm UTC](https://discuss.elastic.co/t/environmental-variable-hostname-in-logstash-yml-and-pipelines-yml-or-logstash-conf/207508 "2019-11-12T12:25:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunilmchaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunilmchaudhari/32/9475_2.png) [@sunilmchaudhari](https://discuss.elastic.co/u/sunilmchaudhari)\
**Post date:** [November 12, 2019, 12:25pm UTC](https://discuss.elastic.co/t/environmental-variable-hostname-in-logstash-yml-and-pipelines-yml-or-logstash-conf/207508/1 "2019-11-12T12:25:20Z")

</div>

I have pipeline id in pipelines.yml=\> pipe-common

I want to give id as pipe-common\_

So the hostname should be dynamic from the environmentla variables of OS level.

I can use ${hostname} variable in shell script. same way, can I use hostname variable in logstash.yml or pipelines.yml or logstash.conf?  
I want to make the configurations so that on any host i can use same dynamic config files and no need to change everytime.  
Anybody has the sampel code for that?

---

<div class="post-metadata">

**Author:** ![willemdh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/willemdh/32/16922_2.png) [@willemdh](https://discuss.elastic.co/u/willemdh)\
**Post date:** [November 13, 2019, 11:50am UTC](https://discuss.elastic.co/t/environmental-variable-hostname-in-logstash-yml-and-pipelines-yml-or-logstash-conf/207508/2 "2019-11-13T11:50:11Z")

</div>

@sunilmchaudhari

See [https://www.elastic.co/guide/en/logstash/current/environment-variables.html](https://www.elastic.co/guide/en/logstash/current/environment-variables.html)

You need to put the ENV variable in /etc/default/logstash on the Logstash node after which you can use the ENV variable with for example ${HOSTNAME} in your pipelines.

Grtz

Willem

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 11, 2019, 11:50am UTC](https://discuss.elastic.co/t/environmental-variable-hostname-in-logstash-yml-and-pipelines-yml-or-logstash-conf/207508/3 "2019-12-11T11:50:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
