# Unable to use env variable with multiple hosts, for ES hosts output

**URL:** https://discuss.elastic.co/t/unable-to-use-env-variable-with-multiple-hosts-for-es-hosts-output/372982
**Category:** Logstash
**Created:** [January 9, 2025, 9:55am UTC](https://discuss.elastic.co/t/unable-to-use-env-variable-with-multiple-hosts-for-es-hosts-output/372982 "2025-01-09T09:55:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Maeris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maeris/32/123964_2.png) [@Maeris](https://discuss.elastic.co/u/Maeris)
#### Post date: [January 9, 2025, 9:55am UTC](https://discuss.elastic.co/t/unable-to-use-env-variable-with-multiple-hosts-for-es-hosts-output/372982/1 "2025-01-09T09:55:32Z")

</div>

Hi,  
I'm running logstash in a k8s cluster using the logstash helm chart.

I have a .env file from which I create a k8s secret, which is used within logstash.

in my .env, I have my hosts defined like:  
`ES_NODES="elk1.host.cloud.com elk2.host.cloud.com elk3.host.cloud.com"`

and in elastic ouput:  
`hosts => "${ES_NODES}"`

This should be correct,  
according to an older topic

> [@How to use environment variable for logstash output elasticsearch plugin for multiple elasticsearch hosts?](https://discuss.elastic.co/t/how-to-use-environment-variable-for-logstash-output-elasticsearch-plugin-for-multiple-elasticsearch-hosts/317169):
>
> Hi, I am deploying logstash and its pipelines via ansible. I want to use the same pipeline on different installations. So I don't want to modify the elasticsearch output plugin in each pipeline. I want to use an environment Variable (configured for each logstash service in /etc/sysconfig/\<LOGSTASH\_SERVICE\_NAME\>. For debugging purpose I exported the environment variable via shell and run a logstash config-test with -t option. My demanded output configuration looks like this, where I want to s…

Yet all I get is the error:

```auto
Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"Java::JavaLang::IllegalStateException", :message=>"Unable to configure plugins: Illegal character in scheme name at index 0: \"elk1.host.cloud.com"

```

Is this k8s specific problem?

---

<div class="post-metadata">

### Author: ![Tortoise](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tortoise/32/147587_2.png) [@Tortoise](https://discuss.elastic.co/u/Tortoise)
#### Post date: [January 9, 2025, 11:33am UTC](https://discuss.elastic.co/t/unable-to-use-env-variable-with-multiple-hosts-for-es-hosts-output/372982/2 "2025-01-09T11:33:42Z")

</div>

Hello,

As per the post shared could you please try to use below :

ES\_NODES="[https://host-01:9200](https://host-01:9200) [https://host-02:9200](https://host-02:9200) [https://host-03:9200](https://host-03:9200)"

Thanks!!

---

<div class="post-metadata">

### Author: ![Maeris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maeris/32/123964_2.png) [@Maeris](https://discuss.elastic.co/u/Maeris)
#### Post date: [January 10, 2025, 8:28pm UTC](https://discuss.elastic.co/t/unable-to-use-env-variable-with-multiple-hosts-for-es-hosts-output/372982/3 "2025-01-10T20:28:31Z")

</div>

I seem to have tried with this pattern as well, but got the same result.

For now I added a separate secret with separate hosts.

---

<div class="post-metadata">

### Author: ![aidofitz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aidofitz/32/51253_2.png) [@aidofitz](https://discuss.elastic.co/u/aidofitz)
#### Post date: [April 10, 2025, 8:47am UTC](https://discuss.elastic.co/t/unable-to-use-env-variable-with-multiple-hosts-for-es-hosts-output/372982/4 "2025-04-10T08:47:35Z")

</div>

Hi,

for info, I had the same prob and solved it with help of this post:

> [@Incorrect ELASTIC\_HOSTS variable in Logstash container](https://discuss.elastic.co/t/incorrect-elastic-hosts-variable-in-logstash-container/355599):
>
> Hi, I have a docker compose file with which I start 3 ES nodes (+ 1 for the setup), 1 Kibana, and 1 Logstash. The 4th ones works well when I deploy, but Logstash crashes. Here is the error I get from logs: [2024-03-18T11:59:04,717][ERROR][logstash.agent] Failed to execute action {:action=\>LogStash::PipelineAction::Create/pipeline\_id:main, :exception=\>"Java::JavaLang::IllegalStateException", :message=\>"Unable to configure plugins: Illegal character in scheme name at index 0: \"https:/…

in short its to do with quotes around the environment variable. In my case I was using docker compose to pass in the environment variable and it seems the initial " character was being passed right through and then being considered part of the URL. Take away the quotes around the list of servers in my docker compose file and it all works. Suspect similar behaviour happening in with other docker / k8s descriptors
