Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lotusnoir committed Sep 15, 2020
0 parents commit 86ad125
Show file tree
Hide file tree
Showing 15 changed files with 533 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
skip_list:
- '106'
- '401'
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
language: python3.6
cache: pip
services: docker

env:
global:
- ROLE_NAME: apps_fluentbit
matrix:
- MOLECULE_DISTRO: ubuntu2004
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: debian10

before_install:
# Upgrade Docker to work with docker-py.
- curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash

install:
# Install test dependencies.
- pip install molecule yamllint ansible-lint docker molecule-goss

before_script:
# To use the role without the ansible github flag
- cd ../
- mv ansible-$ROLE_NAME $ROLE_NAME
- cd $ROLE_NAME

script:
# Run tests.
- molecule test
33 changes: 33 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017-2018 Pawel Krupa, Roman Demachkovych

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Ansible Role: ansible-apps_fluentbit


## Description

[![Build Status](https://travis-ci.com/lotusnoir/ansible-apps_fluentbit.svg?branch=master)](https://travis-ci.com/lotusnoir/ansible-apps_fluentbit)[![License](https://img.shields.io/badge/license-MIT%20License-brightgreen.svg)](https://opensource.org/licenses/MIT)[![Ansible Role](https://img.shields.io/badge/ansible%20role-apps__fluentbit-blue)](https://galaxy.ansible.com/lotusnoir/ansible-apps_fluentbit/)[![GitHub tag](https://img.shields.io/badge/version-latest-blue)](https://github.com/lotusnoir/ansible-apps_fluentbit/tags)

Deploy [fluentbit](https://fluentbit.io/) log forwarder system using ansible.

## Role variables

| Name | Default Value | Description |
| -------------- | ------------- | -----------------------------------|
| `fluentbit_version` | 1.5.6 | fluentbit package version |
| `fluentbit_install_dir` | /etc/fluentbit | fluentbit config directory |

## Examples

---
- hosts: apps_fluentbit
become: yes
become_method: sudo
gather_facts: yes
roles:
- role: ansible-apps_fluentbit
vars:
fluentbit_inputs:
- name: tail
alias: vms
tag: vms
path: /tmp/vms.log
db: /tmp/vms.db
parser: syslog
fluentbit_filters:
- name: modify
alias: add_from_syslog
match: '*'
type: Add
value: 'from_syslog true'
fluentbit_outputs:
- name: null
match: '*'
fluentbit_parsers:
- name: syslog
format: regex
regex: '^(?<register_time>[^ ]*) (?<source>[^ ]*) (?<level>[^ ]*) *(?<message>.*)$'
time_key: time
time_format: '%Y-%m-%dT%H:%M:%S %z'
time_keep: on
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy }}

## License

This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
44 changes: 44 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# Install
fluentbit_version: "1.5.6"
fluentbit_binary_name: '/usr/local/bin/fluent-bit'
fluentbit_nofile_limit: '262144'
fluentbit_install_dir: '/etc/fluent-bit'

# Config file
fluentbit_log_dir: '/var/log/fluentbit.log'
fluentbit_loglevel: 'info'
fluentbit_http_bind: '0.0.0.0'
fluentbit_http_port: '9104'
fluentbit_buffer_path: '/tmp'
fluentbit_buffer_sync: 'normal'
fluentbit_buffer_checksum: 'off'
fluentbit_buffer_mem_limit: '50M'

fluentbit_inputs:
- name: tail
alias: vms
tag: vms
path: /data/vms.log
db: /data/vms.db
parser: syslog
fluentbit_filters:
- name: modify
alias: add_from_syslog
match: '*'
type: Add
value: 'from_syslog true'
fluentbit_outputs:
- name: kafka
alias: Kafka_vms
match: vms
brokers: kafka-01.example.com:9092
topics: syslog_vms
timestamp_format: iso8601
fluentbit_parsers:
- name: syslog
format: regex
regex: '^(?<register_time>[^ ]*) (?<source>[^ ]*) (?<level>[^ ]*) *(?<message>.*)$'
time_key: time
time_format: '%Y-%m-%dT%H:%M:%S %z'
time_keep: on
12 changes: 12 additions & 0 deletions files/fluent-bit.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Fluentbit
Requires=network.target
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.conf
Restart=always

[Install]
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart fluent-bit
service: name=fluent-bit state=restarted
23 changes: 23 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
galaxy_info:
author: "Philippe leal"
description: "Install and configure fluentbit"
role_name: apps_fluentbit
license: "GNU General Public License v3.0"
min_ansible_version: 2.8

platforms:
- name: "Ubuntu"
versions:
- "focal"
- name: "Debian"
versions:
- "buster"

galaxy_tags:
- fluentbit
- logs
- forwarder
- processor

dependencies: []
43 changes: 43 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
changed_when: false
- name: create a test file
file:
path: /tmp/vms.log
state: touch
mode: '0644'

roles:
- role: apps_fluentbit

vars:
fluentbit_inputs:
- name: tail
alias: vms
tag: vms
path: /tmp/vms.log
db: /tmp/vms.db
parser: syslog
fluentbit_filters:
- name: modify
alias: add_from_syslog
match: '*'
type: Add
value: 'from_syslog true'
fluentbit_outputs:
- name: null
match: '*'
fluentbit_parsers:
- name: syslog
format: regex
regex: '^(?<register_time>[^ ]*) (?<source>[^ ]*) (?<level>[^ ]*) *(?<message>.*)$'
time_key: time
time_format: '%Y-%m-%dT%H:%M:%S %z'
time_keep: on
42 changes: 42 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
dependency:
name: galaxy
options:
role-file: requirements.yml

driver:
name: docker

lint: |
yamllint .
platforms:
- name: test-01.dvlp.example.com
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian10}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true

provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
lint: |
ansible-lint
scenario:
name: default
test_sequence:
- destroy
- dependency
- lint
- syntax
- create
- converge
# - verify
- destroy

verifier:
name: goss
Loading

0 comments on commit 86ad125

Please sign in to comment.