# Trouble getting Logstash to pick up an environment variable

**URL:** <https://discuss.elastic.co/t/trouble-getting-logstash-to-pick-up-an-environment-variable/118871>\
**Category:** Logstash\
**Created:** [February 7, 2018, 3:33pm UTC](https://discuss.elastic.co/t/trouble-getting-logstash-to-pick-up-an-environment-variable/118871 "2018-02-07T15:33:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jclose](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jclose](https://discuss.elastic.co/u/jclose)\
**Post date:** [February 7, 2018, 3:33pm UTC](https://discuss.elastic.co/t/trouble-getting-logstash-to-pick-up-an-environment-variable/118871/1 "2018-02-07T15:33:09Z")

</div>

I am consistently getting an error with trying to pick up the environment variable within my input config file.

Here is what I have:

```
input {
    redis {
        data_type => "list"
        key => "syslog"
        host => "${REDIS_HOST}"
        add_field => { "logstash_host" => '${HOSTNAME}'
                       "log_source" => "redis"
                       "msg_src" => "%{[type]}" }
        tags => ["syslog", "redis"]
    }
}

```

It isn't picking up the REDIST\_HOST or the HOSTNAME variables. I have added them to the `/etc/default/logstash` file (this is Ubuntu 16.04). I have even tried doing it via a shell script inside of `/etc/profile.d`

I have tried with both `export REDIS="10.2.2.2"` and just `REDIS="10.2.2.2"` and neither is working.

The error I get is the following:

> [2018-02-07T15:19:49,562][ERROR][logstash.agent] Failed to execute action {:action=\>LogStash::PipelineAction::Create/pipeline\_id:main, :exception=\>"LogStash::ConfigurationError", :message=\>"Cannot evaluate `${REDIS_HOST}`. Environment variable `REDIS_HOST` is not set and there is no default value given.", :backtrace...

I start via a service (`sudo service logstash start`). What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![aberrantCode](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@aberrantCode](https://discuss.elastic.co/u/aberrantCode)\
**Post date:** [February 7, 2018, 3:57pm UTC](https://discuss.elastic.co/t/trouble-getting-logstash-to-pick-up-an-environment-variable/118871/2 "2018-02-07T15:57:16Z")

</div>

Does it work correctly if you run it from the command line with the "--allow-env" switch?

---

<div class="post-metadata">

**Author:** ![jclose](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jclose](https://discuss.elastic.co/u/jclose)\
**Post date:** [February 7, 2018, 3:59pm UTC](https://discuss.elastic.co/t/trouble-getting-logstash-to-pick-up-an-environment-variable/118871/3 "2018-02-07T15:59:10Z")

</div>

I just tried this both, putting both the export and leaving the export out of the /etc/default/logstash file, and the error didn't show up.

I think I have figured out what I was doing wrong.

I was trying to set something inside the /etc/default/logstash file using another, global environment variable. Apparently, it wasn't picking that up.

I'm guessing this was the issue. Apologize for not checking this part more thoroughly.

---

<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:** [March 7, 2018, 3:59pm UTC](https://discuss.elastic.co/t/trouble-getting-logstash-to-pick-up-an-environment-variable/118871/4 "2018-03-07T15:59:33Z")

</div>

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