# Using global variables or reading values from a file

**URL:** <https://discuss.elastic.co/t/using-global-variables-or-reading-values-from-a-file/142618>\
**Category:** Logstash\
**Created:** [August 1, 2018, 3:58pm UTC](https://discuss.elastic.co/t/using-global-variables-or-reading-values-from-a-file/142618 "2018-08-01T15:58:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas.alvarez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lucas.alvarez/32/33649_2.png) [@lucas.alvarez](https://discuss.elastic.co/u/lucas.alvarez)\
**Post date:** [August 1, 2018, 3:58pm UTC](https://discuss.elastic.co/t/using-global-variables-or-reading-values-from-a-file/142618/1 "2018-08-01T15:58:19Z")

</div>

Hello everybody!. I was wondering if there's a way to either define global variables that I can use from the output.conf file or read them from a given file.

My scenario is the following, in 201-output.conf file I have the following code:

```
output {
    if "_grokparsefailure" in [tags] {
        elasticsearch {
            hosts => "..."
            ssl => true
            user => "..."
            password => "..."
            index => "failure_logs"
        }
    }
   ....
}

```

I would like to read the **hosts** , **user** and **password** fields from a file and inject them there.  
I know there's a technology called Logstash Keystore, but as far as I have researched it cannot be automated, you need to manually enter on each machine where Logstash is installed and set the variables that you need to use later on.

Is there a way to accomplish this using a ruby filter?

Thank you all!

---

<div class="post-metadata">

**Author:** ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)\
**Post date:** [August 1, 2018, 5:56pm UTC](https://discuss.elastic.co/t/using-global-variables-or-reading-values-from-a-file/142618/2 "2018-08-01T17:56:29Z")

</div>

It is possible to use variables from your _environment_:

```auto
output {
    if "_grokparsefailure" in [tags] {
        elasticsearch {
            hosts => "${LS_OUTPUT_ES_HOST}"
            ssl => true
            user => "${LS_OUTPUT_ES_USERNAME}"
            password => "${LS_OUTPUT_ES_USERNAME}"
            index => "failure_logs"
        }
    }
    # ....
}

```

It should then be possible to define and export these variables in a shell script:

```bash
export LS_OUTPUT_ES_HOST='123.45.67.89'
export LS_OUTPUT_ES_USER='sekret_user'
export LS_OUTPUT_ES_PASSWORD='$up3r$ekr3t'

```

And, depending on how you start Logstash (e.g., command-line or via a service manager like upstart or initd), adding the following before launching Logstash:

```auto
source path/to/logstash.environment

```

---

<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 29, 2018, 5:56pm UTC](https://discuss.elastic.co/t/using-global-variables-or-reading-values-from-a-file/142618/3 "2018-08-29T17:56:29Z")

</div>

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