概要
Ansibleを使ってfluent-bitをRaspberryPiにインストールします。
プレイブックとテンプレート
マニュアルに書かれている通り、GPG鍵を登録してapt経由でインストールします。
fluent-bit.yaml
- name: Setup fluent-bit
hosts: all
become: true
gather_facts: false
tasks:
- name: Add fluent-bit server’s GPG key
ansible.builtin.apt_key:
url: https://packages.fluentbit.io/fluentbit.key
state: present
- name: Add fluent-bit repository into the sources list
ansible.builtin.apt_repository:
repo: deb https://packages.fluentbit.io/raspbian/bullseye bullseye main
state: present
- name: Install fluent-bit
ansible.builtin.apt:
name: fluent-bit
update_cache: true
- name: Upload a configuration file
ansible.builtin.template:
src: fluent-bit.conf.j2
dest: /etc/fluent-bit/fluent-bit.conf
mode: "0644"
notify:
- config is updated
handlers:
- name: Restart fluent-bit
ansible.builtin.systemd:
name: fluent-bit
state: restarted
listen:
- config is updated
post_tasks:
- name: Ensure fluent-bit is enabled and started
ansible.builtin.systemd:
name: fluent-bit
state: started
enabled: true
設定ファイルのテンプレート下記の通りです。タグにホスト名を追加しています。
templates/fluent-bit.conf.j2
[SERVICE]
# Daemon
# ======
# instruct Fluent Bit to run in foreground or background mode.
#
daemon Off
[INPUT]
name cpu
tag {{ inventory_hostname_short }}.cpu
# Read interval (sec) Default: 1
interval_sec 1
[OUTPUT]
name stdout
match *