14 Commits

Author SHA1 Message Date
04179b04eb fix vars 2026-07-17 12:48:46 +03:00
5cac062a21 variables add port 2026-07-17 12:33:54 +03:00
45f51b67b1 add tests for ubuntu + task: apt update 2026-07-17 12:24:02 +03:00
09ffb32784 Merge pull request #5 from mondrunov-genlab/add-gitlab-role
fix install (retries, until, delay), add deleting tmp-files and fix permissions for alloy.service
2026-07-16 17:17:37 +03:00
5eeec4ad30 fix space 2026-07-16 17:13:42 +03:00
04e5bc7b50 fix spaces and permissions 2026-07-16 17:10:17 +03:00
8f8c56c04e fix permissions-linter and kics 2026-07-16 16:56:23 +03:00
fdb0700e42 fix linter 2026-07-16 16:41:34 +03:00
e46a17e6b5 fix install (retries, until, delay), add deleting tmp-files and fix permissions for alloy.service 2026-07-16 16:31:14 +03:00
6fccc69e03 Merge branch 'master' into add-grafana-alloy-role 2026-07-08 13:30:44 +03:00
4db76ea7cc fix variables in README and permissions in systemd 2026-07-08 13:27:12 +03:00
afd27e2f17 fix parametres for system user 2026-07-06 17:45:27 +03:00
71cd9946c1 split url and port 2026-07-06 16:38:07 +03:00
e5b9415209 Add grafana_alloy role: scrape log files to Loki 2026-07-06 13:43:06 +03:00
6 changed files with 56 additions and 19 deletions

View File

@@ -7,11 +7,11 @@ Install Grafana Alloy from the release binary and configures it to scrape log fi
## Variables
```yaml
alloy_version: "1.17.1"
alloy_config_dir: "/etc/alloy"
alloy_data_dir: "/var/lib/alloy"
alloy_loki_url: "http://localhost:3100/loki/api/v1/push"
alloy_log_paths:
grafana_alloy_version: "1.17.1"
grafana_alloy_config_dir: "/etc/alloy"
grafana_alloy_data_dir: "/var/lib/alloy"
grafana_alloy_loki_url: "http://localhost:3100/loki/api/v1/push"
grafana_alloy_log_paths:
- "/var/log/*.log"
```
@@ -23,8 +23,8 @@ alloy_log_paths:
roles:
- role: grafana_alloy
vars:
alloy_loki_url: "http://loki.example.com:3100/loki/api/v1/push"
alloy_log_paths:
grafana_alloy_loki_url: "http://loki.example.com:3100/loki/api/v1/push"
grafana_alloy_log_paths:
- "/var/log/*.log"
- "/var/log/myapp/*.log"
```

View File

@@ -2,6 +2,8 @@
grafana_alloy_version: "1.17.1"
grafana_alloy_config_dir: "/etc/alloy"
grafana_alloy_data_dir: "/var/lib/alloy"
grafana_alloy_loki_url: "http://localhost:3100/loki/api/v1/push"
grafana_alloy_ui_port: 12345
grafana_alloy_loki_port: 3100
grafana_alloy_loki_url: "http://localhost:{{ grafana_alloy_loki_port }}/loki/api/v1/push"
grafana_alloy_log_paths:
- "/var/log/*.log"

View File

@@ -15,6 +15,15 @@ platforms:
cgroupns_mode: host
privileged: true
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible

View File

@@ -30,7 +30,7 @@
# kics-scan ignore-block
- name: "Check if Alloy is ready"
ansible.builtin.uri:
url: "http://localhost:12345/-/ready"
url: "http://localhost:{{ grafana_alloy_ui_port }}/-/ready"
return_content: true
status_code: 200
method: GET

View File

@@ -4,8 +4,7 @@
name: "alloy"
system: true
shell: "/sbin/nologin"
groups: "adm,systemd-journal"
append: true
groups: "adm"
create_home: false
state: present
@@ -24,26 +23,50 @@
block:
- name: "Install | Check Alloy version"
changed_when: false
failed_when: false
ansible.builtin.command:
cmd: "alloy --version"
register: grafana_alloy_ver
- name: "Install | Assert version correctness"
ansible.builtin.assert:
that: "grafana_alloy_version in grafana_alloy_ver.stdout"
that:
- "grafana_alloy_ver.rc == 0"
- "grafana_alloy_version in grafana_alloy_ver.stdout"
success_msg: "alloy version {{ grafana_alloy_version }} is installed and working"
fail_msg: "alloy version {{ grafana_alloy_version }} is not installed or not working correctly"
rescue:
- name: "Install | Update apt cache on Debian"
ansible.builtin.apt:
update_cache: true
when: ansible_facts["os_family"] == "Debian"
- name: "Install | Ensure unzip is present"
ansible.builtin.package:
name: "unzip"
state: present
- name: "Install | Fetch and unpack the distribution"
- name: "Install | Download the distribution archive"
ansible.builtin.get_url:
url: "https://github.com/grafana/alloy/releases/download/v{{ grafana_alloy_version }}/alloy-linux-amd64.zip"
dest: "/tmp/alloy-linux-amd64.zip"
group: "alloy"
owner: "alloy"
mode: "0644"
timeout: 30
force: true
register: grafana_alloy_download_status
until: grafana_alloy_download_status is success
retries: 3
delay: 5
- name: "Install | Unpack and delete the distribution"
ansible.builtin.unarchive:
src: "https://github.com/grafana/alloy/releases/download/v{{ grafana_alloy_version }}/alloy-linux-amd64.zip"
src: "/tmp/alloy-linux-amd64.zip"
dest: "/tmp"
group: "alloy"
owner: "alloy"
remote_src: true
- name: "Install | Put the binary under the PATH"
@@ -57,8 +80,11 @@
mode: "0755"
- name: "Install | Clean up the downloads"
loop:
- "/tmp/alloy-linux-amd64"
- "/tmp/alloy-linux-amd64.zip"
ansible.builtin.file:
path: "/tmp/alloy-linux-amd64"
path: "{{ item }}"
state: absent
- name: "Install | Create a systemd service unit"
@@ -66,6 +92,6 @@
ansible.builtin.template:
src: alloy.service.j2
dest: /etc/systemd/system/alloy.service
owner: "alloy"
group: "alloy"
mode: "0660"
owner: "root"
group: "root"
mode: "0600"

View File

@@ -16,7 +16,7 @@ ExecStart=/usr/bin/alloy run {{ grafana_alloy_config_dir }}/config.alloy \
ExecReload=/bin/kill -HUP $MAINPID
# Security hardening
ReadWritePaths={{ grafana_alloy_data_dir }}
ReadWritePaths={{ grafana_alloy_data_dir }} {{ grafana_alloy_config_dir }}
ProtectSystem=strict
NoNewPrivileges=true
PrivateTmp=true