87 lines
2.7 KiB
YAML
87 lines
2.7 KiB
YAML
# Ansible Roles for managing Auengun.net Infrastructure & Testing/Learning.
|
|
# Source available at git.auengun.net/homelab/ansible-collection
|
|
# Copyright (C) 2023 GregoryDosh
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
# SPDX-FileCopyrightText: 2023 GregoryDosh
|
|
---
|
|
- name: Install alloy (apt)
|
|
become: true
|
|
when: (GRAFANA_ALLOY_INSTALL | bool) and (ansible_os_family == 'Debian')
|
|
ansible.builtin.apt:
|
|
deb: "{{ GRAFANA_ALLOY_PACKAGE_DEB_URL }}"
|
|
state: present
|
|
|
|
- name: Stat alloy systemd service path
|
|
ansible.builtin.shell: |
|
|
systemctl show alloy | grep Path | cut -f2 -d"=" > /dev/stdout
|
|
changed_when: false
|
|
register: _alloy_systemd_shell
|
|
|
|
- ansible.builtin.set_fact:
|
|
_alloy_systemd_path: "{{ _alloy_systemd_shell.stdout }}"
|
|
|
|
- name: Validate required variables defined.
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "_alloy_systemd_path | length > 0"
|
|
|
|
- name: create alloy default config
|
|
become: true
|
|
ansible.builtin.template:
|
|
src: "{{ role_path }}/templates/etc/default/alloy"
|
|
dest: "/etc/default/alloy"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: "0644"
|
|
register: _alloy_default
|
|
|
|
- name: create alloy config
|
|
become: true
|
|
ansible.builtin.template:
|
|
src: "{{ role_path }}/templates/etc/alloy/config.alloy"
|
|
dest: "/etc/alloy/config.alloy"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: "0644"
|
|
register: _alloy_config
|
|
|
|
- name: Give alloy user access to docker group
|
|
when: GRAFANA_ALLOY_OBSERVE_DOCKER | bool
|
|
become: true
|
|
ansible.builtin.user:
|
|
name: alloy
|
|
groups: docker
|
|
append: true
|
|
|
|
- name: Adjust Alloy systemd server user to root for docker
|
|
become: true
|
|
ansible.builtin.lineinfile:
|
|
path: "{{ _alloy_systemd_path }}"
|
|
regexp: "^User="
|
|
insertafter: "\\[Service\\]"
|
|
line: |
|
|
User=root
|
|
register: _alloy_service_user_changed
|
|
|
|
- name: restart & enable alloy
|
|
when: _alloy_default.changed or _alloy_config.changed or _alloy_service_user_changed.changed
|
|
become: true
|
|
ansible.builtin.service:
|
|
name: "alloy"
|
|
enabled: true
|
|
state: restarted
|
|
daemon_reload: true
|