# Cannot access environment variables

**URL:** <https://discuss.elastic.co/t/cannot-access-environment-variables/288928>\
**Category:** Logstash\
**Created:** [November 10, 2021, 9:31pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928 "2021-11-10T21:31:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tofubeats](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tofubeats](https://discuss.elastic.co/u/tofubeats)\
**Post date:** [November 10, 2021, 9:31pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/1 "2021-11-10T21:31:41Z")

</div>

Hi,

My config is really simple, I'm just trying to get a simple envornment variable to be accessed and used by a Logstash pipeline. It looks like this:

```auto
input{
  file {  
    path => "${test}"
  }
}

filter {}

output {
 stdout{ }       
}

```

before I run this config I exported the path like this:  
`export path="/path/to/file/*.csv"`

And I get this error:  
`"Unable to configure plugins: Cannot evaluate ${test}. Replacement variable test is not defined in a Logstash secret store or an environment entry and there is no default value given.`

The docs don't indicate that I need to do anything other than export the variable but I can't figure it out. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [November 10, 2021, 9:37pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/2 "2021-11-10T21:37:16Z")

</div>

The name of variable should match the name you export it as.

```auto
export PATH="/path/to/file/*.csv"

```

```auto
path => "${PATH}"

```

---

<div class="post-metadata">

**Author:** ![tofubeats](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tofubeats](https://discuss.elastic.co/u/tofubeats)\
**Post date:** [November 10, 2021, 9:40pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/3 "2021-11-10T21:40:42Z")

</div>

sorry, that was a typo.

the variable exported is in fact `test` and i validated that by running `env` and seeing the `test` variable there.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [November 10, 2021, 9:41pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/4 "2021-11-10T21:41:43Z")

</div>

How are you running logstash?

---

<div class="post-metadata">

**Author:** ![tofubeats](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tofubeats](https://discuss.elastic.co/u/tofubeats)\
**Post date:** [November 10, 2021, 9:46pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/5 "2021-11-10T21:46:14Z")

</div>

from the command line with this line:

```auto
sudo /usr/share/logstash/bin/logstash -f /home/varTest.config

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [November 10, 2021, 9:54pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/6 "2021-11-10T21:54:43Z")

</div>

You are exporting the variable as a normal user and running logstash with sudo, which runs under `root` and the `root` user environment does not have the variable you exported before.

To solve this you need to tell sudo to preserve the variable.

Something like this:

```auto
$ export VARNAME="VALUE"
$ sudo --preserve-env=VARNAME /usr/share/logstash/bin/logstash -f /home/varTest.config

```

You can also run this way:

```auto
$ sudo VARNAME="VALUE" /usr/share/logstash/bin/logstash -f /home/varTest.config

```

---

<div class="post-metadata">

**Author:** ![tofubeats](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tofubeats](https://discuss.elastic.co/u/tofubeats)\
**Post date:** [November 15, 2021, 5:47pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/7 "2021-11-15T17:47:10Z")

</div>

That worked, thank you!

---

<div class="post-metadata">

**Author:** ![tofubeats](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tofubeats](https://discuss.elastic.co/u/tofubeats)\
**Post date:** [November 15, 2021, 6:15pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/8 "2021-11-15T18:15:16Z")

</div>

Can I ask if there are any similar nuances when using variables in pipelines that are configured and set up within the Elastic UI?

---

<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 13, 2021, 6:15pm UTC](https://discuss.elastic.co/t/cannot-access-environment-variables/288928/9 "2021-12-13T18:15:56Z")

</div>

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