# Does Elasticsearch pick up OS environment variable automatically, or I have to reference it in elasticsearch.yml explicitly

**URL:** <https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810>\
**Category:** Elasticsearch\
**Created:** [March 18, 2019, 3:51pm UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810 "2019-03-18T15:51:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![morningspace](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/morningspace/32/40398_2.png) [@morningspace](https://discuss.elastic.co/u/morningspace)\
**Post date:** [March 18, 2019, 3:51pm UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810/1 "2019-03-18T15:51:25Z")

</div>

I was using "reindex.remote.whitelist" to configure whitelist hosts for my remote reindex. Previously, I define that as normal environment variable w/o touching elasticsearch.yml. This works perfect on my local machine. So, when you check elasticsearch.yml, no reindex.remote.whitelist there, and if you printenv in OS terminal, you will see the environment variable being listed, e.g. reindex.remote.whitelist=my-elasticsearch:9200.

However, recently I was deploying the same stuff on a different env, where I got the error: [my-elasticsearch:9200] not whitelisted in reindex.remote.whitelist. If I check the /\_cluster/settings, I do see reindex.remote.whitelist is empty.

It makes me a bit confusing. Does it mean I have to define that in elasticsearch.yml at first with a placeholder for the environment variable to be replaced later... Just like this:

```auto
# In elasticsearch.yml
reindex.remote.whitelist: "${REINDEX_REMOTE_WHITELIST}"

```

Then export REINDEX\_REMOTE\_WHITELIST in OS terminal.

Anything I missed?

BTW: I was trying to read the source code to understand where the code picks up the settings... I can see the Settings object being passed into TransportReindexAction, but still have no idea where the Settings object comes from ☹

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [March 19, 2019, 7:35am UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810/2 "2019-03-19T07:35:51Z")

</div>

I would say no, it doesn't. But is you realy need that, may be you can pass the variable as a param of the JVM in jmv.options ?

---

<div class="post-metadata">

**Author:** ![morningspace](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/morningspace/32/40398_2.png) [@morningspace](https://discuss.elastic.co/u/morningspace)\
**Post date:** [March 19, 2019, 11:11am UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810/3 "2019-03-19T11:11:43Z")

</div>

Thanks @xavierfacq... well, actually I'm wrapping elasticsearch into Docker container... In prod env, we use K8s, while on my local machine, I use Docker Compose to instrument the env vars. But I think either way they are the same essentially.

Interestingly, when I use docker-compose.yml locally, and define the env var like this:

```auto
  elasticsearch:
    ...
    environment:
      reindex.remote.whitelist: elasticsearch-old:9200
      REINDEX_REMOTE_WHITELIST: elasticsearch-new:9200

```

Then in elasticsearch.yml:

```auto
reindex.remote.whitelist: "${REINDEX_REMOTE_WHITELIST}"

```

If I comment the first line in environment section in docker-compose.yml, launch the container, then check the \_cluster/settings?include\_defaults=true, I can see the value of reindex.remote.whitelist is `elasticsearch-new:9200`;

If I comment the second line, the value will be `elasticsearch-old:9200`;

If I keep both uncommented, the value will be `elasticsearch-old:9200`! It looks to define `reindex.remote.whitelist` as env var will have the higher priority than the other one. Really curious about what's the magic happened behind...

P.S.  
I'd say to define `reindex.remote.whitelist` as env var directly may not be a common way?... Actually people cannot export env var w/ dots like this in Bash. But I do see that works on my local... Just it doesn't work in prod env... which makes me confused... is that because of the OS difference? I'm using the official Docker image on local which is based on CentOS, while in prod env, we use a self-created image based on Alpine...

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [March 20, 2019, 7:30am UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810/4 "2019-03-20T07:30:25Z")

</div>

Hi,

Ok, did you solve your problem ? I don't known Docker very well but in my various, I used to define values by a command argument in the Dockerfile:

```
-e "transport.host=172.17.0.2"

```

or

by copying a file

```
ADD localconfdir/elasticsearch.yml /usr/share/elasticsearch/config/

```

bye,  
Xavier

---

<div class="post-metadata">

**Author:** ![morningspace](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/morningspace/32/40398_2.png) [@morningspace](https://discuss.elastic.co/u/morningspace)\
**Post date:** [March 20, 2019, 11:48am UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810/5 "2019-03-20T11:48:33Z")

</div>

Hi @xavierfacq it's fine to use ENV or ADD in Dockerfile, either way is ok... Just different ways to define environment variable. The point that makes me curious is that, after I define the environment variable:

1. Do I have to explicitly reference it in elasticsearch.yml, or...
2. Elasticsearch can recognize it w/o adding that into elasticsearch.yml...

Based on what I tested locally, it seems 2) is always true, until I got the issue a couple of days ago that I described above... I found in another env, not my local env, `reindex.remote.whitelist` is empty even I set it as environment variable... So, I have to go back to 1). That seems the official way that's documented on Elasticsearch online documentation. Something like:

```auto
export reindex.remote.whitelist=blablabla

```

vs.

```auto
export REINDEX_REMOTE_WHITELIST=blablabla
+
reindex.remote.whitelist: "${REINDEX_REMOTE_WHITELIST}" # in elasticsearch.yml

```

Ideally, I should have figured out the magic behind by going through the Elasticsearch code, but I am still new to the code... it seems not very easy to understand the overall flow of how that's picking up the environment variable for its configuration.

---

<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:** [April 17, 2019, 11:48am UTC](https://discuss.elastic.co/t/does-elasticsearch-pick-up-os-environment-variable-automatically-or-i-have-to-reference-it-in-elasticsearch-yml-explicitly/172810/6 "2019-04-17T11:48:36Z")

</div>

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