# Filebeat configuration file cannot retrieve local environment variables

**URL:** https://discuss.elastic.co/t/filebeat-configuration-file-cannot-retrieve-local-environment-variables/376104
**Category:** Beats
**Tags:** filebeat
**Created:** [March 19, 2025, 2:52am UTC](https://discuss.elastic.co/t/filebeat-configuration-file-cannot-retrieve-local-environment-variables/376104 "2025-03-19T02:52:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pacoxpk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pacoxpk/32/131393_2.png) [@pacoxpk](https://discuss.elastic.co/u/pacoxpk)
#### Post date: [March 19, 2025, 2:52am UTC](https://discuss.elastic.co/t/filebeat-configuration-file-cannot-retrieve-local-environment-variables/376104/1 "2025-03-19T02:52:22Z")

</div>

Filebeat version: 8.12.0  
The configuration of filebeat.yml is as follows

```auto
filebeat.config.inputs:
  enabled: true
  path: /etc/filebeat/conf.d/*.yml

processors:
  - add_fields:
      fields:
        environment: prod
        from: $(IP)
  - drop_fields:
      fields: ["agent.ephemeral_id","agent.name","log.offset", "host.os.codename", "_id", "host.name", "host.id", "agent.version", "ecs.version", "agent.id", "@version", "version", "fields.index", "input.type", "_type", "agent.type","beats_input_codec_plain_applied","type.keyword"]

output.logstash:
  hosts: ["10.1.100.64:5045"]

logging.level: info
logging.to_files: true
logging.files:
  path: /var/log/filebeat/
  name: filebeat
  keepfiles: 7
  permissions: 0644

```

In the environment variable configuration file, add the following statement:

```auto
export IP=$(hostname -I|awk '{print $1}')

```

And load the application using source/etc/profile  
The local IP address can be obtained normally through echo $IP, but there is an error when starting the Filebeat service. The following are the logs related to the service startup error

```auto
{"log.level":"error","@timestamp":"2025-03-19T10:50:47.700+0800","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.handleError","file.name":"instance/beat.go","file.line":1312},"message":"Exiting: error initializing processors: fail to unpack the add_fields configuration: missing field accessing 'processors.0.add_fields.fields.from' (source:'/etc/filebeat/filebeat.yml')","service.name":"filebeat","ecs.version":"1.6.0"}

```

How to write a configuration file and add the field "from" to obtain the local IP address

---

<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: [March 19, 2025, 3:59am UTC](https://discuss.elastic.co/t/filebeat-configuration-file-cannot-retrieve-local-environment-variables/376104/2 "2025-03-19T03:59:53Z")

</div>

> [@pacoxpk](#):
>
> `from: $(IP)`

This seems wrong, according to the [documentation](https://www.elastic.co/guide/en/beats/filebeat/current/using-environ-vars.html) it should be something like this:

```auto
from: '${IP}'

```

How are you starting filebeat? As a service?

---

<div class="post-metadata">

### Author: ![pacoxpk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pacoxpk/32/131393_2.png) [@pacoxpk](https://discuss.elastic.co/u/pacoxpk)
#### Post date: [March 19, 2025, 5:20am UTC](https://discuss.elastic.co/t/filebeat-configuration-file-cannot-retrieve-local-environment-variables/376104/3 "2025-03-19T05:20:28Z")

</div>

Thanks for your reply  
Using the above method and attempting to start the Filebeat service, the error message that appears is consistent with the one above

```auto
Exiting: error initializing processors: fail to unpack the add_fields configuration: missing field accessing 'processors.0.add_fields.fields.from' (source:'/etc/filebeat/filebeat.yml')

```

---

<div class="post-metadata">

### Author: ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)
#### Post date: [March 19, 2025, 8:58am UTC](https://discuss.elastic.co/t/filebeat-configuration-file-cannot-retrieve-local-environment-variables/376104/4 "2025-03-19T08:58:00Z")

</div>

I am unclear here.

You added `export IP=$(hostname -I|awk '{print $1}')` to /etc/profile ?

> [@pacoxpk](#):
>
> And load the application using source/etc/profile

and then you executed

`source /etc/profile`

in some shell and restarted filebeat service?
