diff --git a/roles/alloy/README.md b/roles/alloy/README.md index f1f0198b..2ec0e4d4 100644 --- a/roles/alloy/README.md +++ b/roles/alloy/README.md @@ -19,13 +19,13 @@ Available variables with their default values are listed below (`defaults/main.y | `arch` | The architecture of the current machine. | Based on `ansible_architecture` lookup, defaults to 'amd64'. | | `binary_url` | URL to Grafana Alloy binary for the specific version and architecture. | Constructed URL based on `version` and `arch` variables. | | `service_name` | The name to be used for the Grafana Alloy service. | "alloy" | -| `installation_dir` | Directory where Grafana Alloy is to be installed. | "/etc/alloy" | +| `installation_dir` | Directory where Grafana Alloy binary is to be installed. Must be present. | "/usr/local/bin" | | `environment_file` | Name of the environment file for the Grafana Alloy service. | "service.env" | | `config_dir` | Directory for Grafana Alloy configuration. | "/etc/alloy" | | `config_file` | Configuration file name for Grafana Alloy. | "config.river" | | `service_user` | User under which the Grafana Alloy service will run. | "alloy" | | `service_group` | Group under which the Grafana Alloy service will run. | "alloy" | -| `working_dir` | Working directory for the Grafana Alloy service. | "/etc/alloy" | +| `working_dir` | Working directory for the Grafana Alloy service. | "/var/lib/alloy" | | `env_file_vars` | Additional environment variables to be set in the service environment file. | {} (Empty dictionary) | | `alloy_flags_extra` | Extra flags to pass to the Alloy service. | {} (Empty dictionary) | | `start_after_service` | Specify an optional dependency service Alloy should start after. | '' (Empty string) | diff --git a/roles/alloy/defaults/main.yml b/roles/alloy/defaults/main.yml index e9de0973..3f00bd9d 100644 --- a/roles/alloy/defaults/main.yml +++ b/roles/alloy/defaults/main.yml @@ -13,7 +13,7 @@ binary_url: "https://github.com/grafana/alloy/releases/download/v{{ version }}/a service_name: "alloy" -installation_dir: "/etc/alloy" +installation_dir: "/usr/local/bin" environment_file: "service.env" @@ -25,7 +25,7 @@ service_user: "alloy" service_group: "alloy" -working_dir: "/etc/alloy" +working_dir: "/var/lib/alloy" env_file_vars: {} diff --git a/roles/alloy/tasks/configure.yml b/roles/alloy/tasks/configure.yml index 6a9f7790..61e5220b 100644 --- a/roles/alloy/tasks/configure.yml +++ b/roles/alloy/tasks/configure.yml @@ -1,3 +1,12 @@ +- name: Create alloy working directory + ansible.builtin.file: + path: "{{ working_dir }}" + state: directory + owner: "{{ service_user }}" + group: "{{ service_group }}" + mode: "0755" + become: true + - name: Create alloy config directory ansible.builtin.file: path: "{{ config_dir }}" diff --git a/roles/alloy/tasks/install.yml b/roles/alloy/tasks/install.yml index 967d73c3..2ee35999 100644 --- a/roles/alloy/tasks/install.yml +++ b/roles/alloy/tasks/install.yml @@ -26,22 +26,13 @@ become: true register: download_result -- name: Remove existing alloy installation directory +- name: Remove existing alloy binary ansible.builtin.file: - path: "{{ installation_dir }}" + path: "{{ installation_dir }}/alloy-linux-{{ arch }}" state: absent become: true when: download_result.changed -- name: Create alloy installation directory - ansible.builtin.file: - path: "{{ installation_dir }}" - state: directory - mode: '0755' - owner: "{{ service_user }}" - group: "{{ service_group }}" - become: true - - name: Extract alloy binary ansible.builtin.unarchive: src: "/tmp/alloy-{{ version }}.zip" diff --git a/roles/alloy/templates/alloy.service.j2 b/roles/alloy/templates/alloy.service.j2 index 5e56b330..78626e3e 100644 --- a/roles/alloy/templates/alloy.service.j2 +++ b/roles/alloy/templates/alloy.service.j2 @@ -9,7 +9,7 @@ Restart=always User={{ service_user }} Group={{ service_group }} Environment=HOSTNAME=%H -EnvironmentFile={{ installation_dir }}/{{ environment_file }} +EnvironmentFile={{ config_dir }}/{{ environment_file }} WorkingDirectory={{ working_dir }} ExecStart={{ installation_dir }}/alloy-linux-{{ arch }} run \ {% for flag, flag_value in alloy_flags_extra.items() %}