# Using environment variables in elasticsearch config file

**URL:** <https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390>\
**Category:** Elasticsearch\
**Created:** [July 31, 2020, 7:16pm UTC](https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390 "2020-07-31T19:16:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cms95](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cms95](https://discuss.elastic.co/u/cms95)\
**Post date:** [July 31, 2020, 7:16pm UTC](https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390/1 "2020-07-31T19:16:41Z")

</div>

Im trying to use environment variables to define network.host. Ive tried ${var}, var, "{var}", etc all with no luck.

ive tried doing whats mentioned here too: [https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html)

Is this possible? Ill attach my yml file.

![image](https://us1.discourse-cdn.com/elastic/original/3X/9/9/9946b00a6249692b805b5e2a5abe2651049a2374.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/9/499dcf3d2c1e79fb98d5fd84297d8931d5f0f848.png)

---

<div class="post-metadata">

**Author:** ![cms95](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cms95](https://discuss.elastic.co/u/cms95)\
**Post date:** [July 31, 2020, 7:19pm UTC](https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390/2 "2020-07-31T19:19:07Z")

</div>

```auto
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: Elastic-Cluster1
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: ${MY_ADDRESS} 
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

```

---

<div class="post-metadata">

**Author:** ![cms95](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@cms95](https://discuss.elastic.co/u/cms95)\
**Post date:** [July 31, 2020, 7:22pm UTC](https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390/3 "2020-07-31T19:22:48Z")

</div>

Also I have verified this works fine when i use my address instead of the env variable

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 3, 2020, 9:37am UTC](https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390/4 "2020-08-03T09:37:44Z")

</div>

You seem to start Elasticsearch via `systemd`, which does not take environment variables into account, but requires to set them explicitely.

See [https://coreos.com/os/docs/latest/using-environment-variables-in-systemd-units.html](https://coreos.com/os/docs/latest/using-environment-variables-in-systemd-units.html)

What you tried above would work, if you started Elasticsearch without systemd though!

---

<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:** [August 31, 2020, 9:37am UTC](https://discuss.elastic.co/t/using-environment-variables-in-elasticsearch-config-file/243390/5 "2020-08-31T09:37:45Z")

</div>

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