# Several log formatting with ansible loop

**URL:** <https://discuss.elastic.co/t/several-log-formatting-with-ansible-loop/112387>\
**Category:** Logstash\
**Created:** [December 19, 2017, 9:17am UTC](https://discuss.elastic.co/t/several-log-formatting-with-ansible-loop/112387 "2017-12-19T09:17:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juliatzin\_Ixtekakati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juliatzin_ixtekakati/32/25784_2.png) [@Juliatzin\_Ixtekakati](https://discuss.elastic.co/u/Juliatzin_Ixtekakati)\
**Post date:** [December 19, 2017, 9:17am UTC](https://discuss.elastic.co/t/several-log-formatting-with-ansible-loop/112387/1 "2017-12-19T09:17:18Z")

</div>

Hi,

I have an ansible dictionary where I define all my logfiles to parse and what it the format of the message:

logstash.conf

```auto
grok {
  match => [
"message", '%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST:dockerhost} %{DATA:conteneur}(?:\[%{POSINT:pid}\])( time="%{TIMESTAMP_ISO8601:logtime}")?( level=%{LOGLEVEL:severity})?( msg=)?%{GREEDYDATA:message}'
  ],
"message", '%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST:dockerhost} %{DATA:conteneur}'
  ],
}

```

Don't focus on the syntax, because I still don't work on differents formats that message will have, it is just an example.

I get it from logstash.conf.j2

```auto
  grok {
    match => [
    {% for log in filebeat_dict.filebeat.logs | default([]) %}
      "message" => "{{ log.format }}",
    {% endfor %}
    ]
  }

```

Here is my ansible dictionary:

```auto
logs:
      - path: "/var/log/docker"
        app_id: "docker"
        format: '%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST:dockerhost} %{DATA:conteneur}(?:\[%{POSINT:pid}\])?:?:( time="%{TIMESTAMP_ISO8601:logtime}")?( level=%{LOGLEVEL:severity})?( msg=)?%{GREEDYDATA:message}'
      - path: "/data/nexus/data/log"
        app_id: "nexus"
        format: '%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST:dockerhost} %{DATA:conteneur}'

```

I have 2 questions for that:

- Is it the correct approach ?
- For the last line, I will always have a last comma that make logstash fail. How should I get rid of the last comma ???

Thanks for your help!

---

<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:** [January 16, 2018, 9:17am UTC](https://discuss.elastic.co/t/several-log-formatting-with-ansible-loop/112387/2 "2018-01-16T09:17:23Z")

</div>

Closed on January 16, 2018, 9:17am UTC

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