# Beats (Metricbeat) config not accepting environment variables

**URL:** https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574
**Category:** Beats
**Created:** [December 20, 2016, 1:22pm UTC](https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574 "2016-12-20T13:22:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![leigh](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@leigh](https://discuss.elastic.co/u/leigh)
#### Post date: [December 20, 2016, 1:22pm UTC](https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574/1 "2016-12-20T13:22:32Z")

</div>

Hi,  
We are using Env Vars in our metricbeat.yml file but they are not getting picked up when restarting the service. Metricbeat 5.1.1.

This is basically the same question as answered here:

> [@Accessing environment variable in config file in a custom made beats](https://discuss.elastic.co/t/accessing-environment-variable-in-config-file-in-a-custom-made-beats/62241):
>
> I have built a custom made beats based on libbeat and I want to use environment variable as a value in the config file. However, if I type ${VAR} in the config file and I run config test, I got: ./countbeat -c countbeat.yml --configtest Exiting: error unpacking config data: missing field accessing 'name' (source:'countbeat.yml') I tried in line of configuring the name of the shipper: name: "${HOSTNAME}" And it works if I change it into a static string: name: "a\_name" I have tried to use t…

But...we are _exporting the Env Var_ just before restarting the service and doing this under root (same user that metricbeat service is running under).

````auto
fields:
   field1: ${THEFIELD}```

```sudo su
export THEFIELD=thevalue
service metricbeat restart```

>Exiting: error unpacking config data: missing field accessing 'fields.field1' (source:'/etc/metricbeat/metricbeat.yml')
   ...fail!

Any ideas?
````

---

<div class="post-metadata">

### Author: ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)
#### Post date: [December 21, 2016, 12:51pm UTC](https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574/2 "2016-12-21T12:51:53Z")

</div>

is the `service` command really picking up environment variables? Looks like `service` is actually dropping environment variables when starting daemons.

---

<div class="post-metadata">

### Author: ![leigh](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@leigh](https://discuss.elastic.co/u/leigh)
#### Post date: [January 5, 2017, 12:40pm UTC](https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574/3 "2017-01-05T12:40:44Z")

</div>

Thanks Steffen you are right. I misunderstood the behaviour of the `service` command. The metricbeat doc states

> After changing the value of an environment variable, you need to restart Metricbeat to pick up the new value.

What is best practice for restarting Metricbeat if we cannot use the `service` command?

---

<div class="post-metadata">

### Author: ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)
#### Post date: [January 5, 2017, 2:06pm UTC](https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574/4 "2017-01-05T14:06:55Z")

</div>

I wouldn't use an environment variable here. The problem with service startup is, is your environment variable already available by init-process (most likely not).

Either update your config file or the startup script.

[See google](https://www.google.de/search?rls=en&q=redhat+service+pass+environment+variable&ie=UTF-8&oe=UTF-8)

---

<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: [January 10, 2017, 1:22pm UTC](https://discuss.elastic.co/t/beats-metricbeat-config-not-accepting-environment-variables/69574/5 "2017-01-10T13:22:32Z")

</div>

This topic was automatically closed after 21 days. New replies are no longer allowed.
