Skip to content

Instantly share code, notes, and snippets.

@fopina
Created July 9, 2019 23:18

Revisions

  1. fopina created this gist Jul 9, 2019.
    6 changes: 6 additions & 0 deletions handlers_main.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ---
    - name: Restart Fluentbit
    service:
    name: td-agent-bit
    enabled: true
    state: restarted
    26 changes: 26 additions & 0 deletions tasks_main.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    - name: Required variable check
    fail:
    msg: "both fluentbit_inputs and fluentbit_outputs variables are required"
    when: fluentbit_inputs is not defined or fluentbit_outputs is not defined

    - name: add fluentbit apt key
    apt_key:
    url: https://packages.fluentbit.io/fluentbit.key
    state: present

    - apt_repository:
    repo: deb https://packages.fluentbit.io/{{ ansible_lsb.id | lower }}/{{ ansible_lsb.codename }} {{ ansible_lsb.codename }} main
    state: present
    filename: fluentbit
    when: ansible_lsb.codename in ('stretch', 'jessie') and ansible_lsb.id in ('Debian', 'Raspbian')

    - name: Install td-agent-bit
    apt:
    name: td-agent-bit
    notify: Restart Fluentbit

    - name: generate td-agent-bit config
    template:
    src: td-agent-bit.conf.j2
    dest: /etc/td-agent-bit/td-agent-bit.conf
    notify: Restart Fluentbit
    52 changes: 52 additions & 0 deletions templates_td-agent-bit.conf.j2
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    [SERVICE]
    Flush 5
    Daemon Off
    Log_Level info

    Parsers_File parsers.conf
    Plugins_File plugins.conf

    HTTP_Server Off
    HTTP_Listen 0.0.0.0
    HTTP_Port 2020

    {% for input in fluentbit_inputs %}
    {% for input_name, input_props in input.items() %}
    [INPUT]
    Name {{ input_name }}
    {% for prop in input_props %}
    {% for pk, pv in prop.items() %}
    {{ pk }} {{ pv }}
    {% endfor %}
    {% endfor %}
    {% endfor %}

    {% endfor %}

    {% if fluentbit_filters is defined %}
    {% for filter in fluentbit_filters %}
    {% for filter_name, filter_props in filter.items() %}
    [FILTER]
    Name {{ filter_name }}
    {% for prop in filter_props %}
    {% for pk, pv in prop.items() %}
    {{ pk }} {{ pv }}
    {% endfor %}
    {% endfor %}
    {% endfor %}

    {% endfor %}
    {% endif %}

    {% for output in fluentbit_outputs %}
    {% for output_name, output_props in output.items() %}
    [OUTPUT]
    Name {{ output_name }}
    {% for prop in output_props %}
    {% for pk, pv in prop.items() %}
    {{ pk }} {{ pv }}
    {% endfor %}
    {% endfor %}
    {% endfor %}

    {% endfor %}