# Cannot use env variables in filebeat!

**URL:** <https://discuss.elastic.co/t/cannot-use-env-variables-in-filebeat/94270>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [July 24, 2017, 4:59am UTC](https://discuss.elastic.co/t/cannot-use-env-variables-in-filebeat/94270 "2017-07-24T04:59:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaohua](https://avatars.discourse-cdn.com/v4/letter/y/3be4f8/32.png) [@Yaohua](https://discuss.elastic.co/u/Yaohua)\
**Post date:** [July 24, 2017, 4:59am UTC](https://discuss.elastic.co/t/cannot-use-env-variables-in-filebeat/94270/1 "2017-07-24T04:59:22Z")

</div>

My filebeat version is 5.5.0 and OS is CentOS7  
###The config as following:

```auto
filebeat.prospectors:
- input_type: log
  paths:
    - /var/log/xaa
  fields:
    docker: ${HOSTNAME}
  fields_under_root: true
  document_type: nginx
  tags: test

[root@vm1 ~]# env|grep HOSTNAME
HOSTNAME=vm1

```

**but the filebeat cann't work.**  
##The log output

> CRIT Exiting: error loading states for prospector 8734646245685621701: missing field accessing 'filebeat.prospectors.0.fields.docker' (source:'/etc/filebeat/filebeat.yml')

**The filebeat is working when I change the ${HOSTNAME} to ${HOSTNAME:default\_value},But it's error when I change the ${HOSTNAME} to ${HOSTNAME:?default\_value}.**

---

<div class="post-metadata">

**Author:** ![Yaohua](https://avatars.discourse-cdn.com/v4/letter/y/3be4f8/32.png) [@Yaohua](https://discuss.elastic.co/u/Yaohua)\
**Post date:** [July 24, 2017, 5:40am UTC](https://discuss.elastic.co/t/cannot-use-env-variables-in-filebeat/94270/2 "2017-07-24T05:40:40Z")

</div>

I got it.  
I execute the `systemctl import-environment` the filebeat is working

---

<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 21, 2017, 5:40am UTC](https://discuss.elastic.co/t/cannot-use-env-variables-in-filebeat/94270/3 "2017-08-21T05:40:54Z")

</div>

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