# Environment variable error

**URL:** https://discuss.elastic.co/t/environment-variable-error/156709
**Category:** Beats
**Tags:** filebeat
**Created:** [November 14, 2018, 4:33pm UTC](https://discuss.elastic.co/t/environment-variable-error/156709 "2018-11-14T16:33:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![YvorL](https://avatars.discourse-cdn.com/v4/letter/y/9fc348/32.png) [@YvorL](https://discuss.elastic.co/u/YvorL)
#### Post date: [November 14, 2018, 4:33pm UTC](https://discuss.elastic.co/t/environment-variable-error/156709/1 "2018-11-14T16:33:18Z")

</div>

Hi!

There isn't too many documents or threads on this issue and I reckon it isn't used too much.

I've several **external** configuration files to make updating more dynamic. I'd like to add environment variables to these which are being reloaded every X minutes.  
Unfortunately, when I tried to add a custom variable, I get this in the log:

> ERROR [reload] cfgfile/list.go:104 Error creating runner from config: missing field accessing ...

External configuration file:

```
- type: log
  paths:
    - /var/log/*.log
  scan_frequency: 1m
  close_renamed: true
  fields_under_root: true
  fields:
    custom_var: "${FOO}"

```

\_.profile

```
...
export FOO="BAR"

```

Filebeat version: 6.4.3  
OS: Ubuntu 18.04  
Filebeat is running as a service by _root_.  
The variable is defined in _root_'s '.profile', bash is returning the value.  
The variable is intentionally available for only _root_.

Thank you

---

<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: [November 15, 2018, 3:21pm UTC](https://discuss.elastic.co/t/environment-variable-error/156709/2 "2018-11-15T15:21:52Z")

</div>

The '.profile' file is read by bash only. I think with ubuntu 18.04 the systemd service file is used to start filebeat. In order to add environment variables to a process managed by systemd use the `Environment=FOO=BAR` directive or use the `EnvironmentFile` directive, so you can manage environment variables in a different file.

---

<div class="post-metadata">

### Author: ![YvorL](https://avatars.discourse-cdn.com/v4/letter/y/9fc348/32.png) [@YvorL](https://discuss.elastic.co/u/YvorL)
#### Post date: [November 15, 2018, 4:16pm UTC](https://discuss.elastic.co/t/environment-variable-error/156709/3 "2018-11-15T16:16:18Z")

</div>

I'm sorry, but could you please be a bit more specific? I'm not well versed in this topic and not sure what you are referring to by those two directives. For Ubuntu I found an "/etc/environment" file, but that's system wide which isn't implementable for us since non-root users mustn't get those information.  
As I wrote earlier, want to spare the time to overwrite changes in all existing files.

Thank you!

---

<div class="post-metadata">

### Author: ![YvorL](https://avatars.discourse-cdn.com/v4/letter/y/9fc348/32.png) [@YvorL](https://discuss.elastic.co/u/YvorL)
#### Post date: [November 21, 2018, 9:17am UTC](https://discuss.elastic.co/t/environment-variable-error/156709/4 "2018-11-21T09:17:29Z")

</div>

If anyone wonders how to achieve what _steffens_ wrote, here's one way. Please note, that

- You need `root` privilege
- In case, you don't know what implications does this flow have, please consult with a system administrator (as I have)

1. Create a file where you'll store your environment variables (e.g., _env\_vars.conf_ or _environmentVars_).
2. Populate the file with variables (as many as you need):

> MyVar1="This is one"  
> myvar2="polar bear v1.2"

```
_Note_:
Environment variables are case sensitive!
There are predefined variables which you shouldn't overwrite (consult with a sysadmin/read manual).
It's a good practice to have all variables encapsulated by quotation mark ( **"** ).

```

1. Execute `systemctl edit filebeat.service` in the terminal and add these lines:

> [Service]  
> EnvironmentFile=/etc/somefolder/env\_vars.conf

1. Add the environment variables to your Filebeat configuration (using `${MyVar1}` format).
2. Restart Filebeat service: `systemctl restart filebeat.service`

And you're good to go. I'm not sure that this is the best way to achieve dynamic variables, but it works for my case 🙂  
**Important note** : Every time you change these variables (update the file), you need to restart the Filebeat service since those are read once at startup.

---

<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: [November 21, 2018, 2:35pm UTC](https://discuss.elastic.co/t/environment-variable-error/156709/5 "2018-11-21T14:35:49Z")

</div>

Sorry, I totally missed you asking how to do.

This is a very good solutions for users running systemd. Thank you for sharing.

Also check the ownership and access rights to the file with environment variables. Filebeat normally checks it is the only owner of it's config file (belongs to root and no other can write to it). As the file with environment variables is read by systemd, we can't do these checks.

---

<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 19, 2018, 2:35pm UTC](https://discuss.elastic.co/t/environment-variable-error/156709/6 "2018-12-19T14:35:58Z")

</div>

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