Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alloy: Fix env file location #211

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roles/alloy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
4 changes: 2 additions & 2 deletions roles/alloy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
version: "1.0.0"

Check failure on line 1 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: version)

arch_mapping:

Check failure on line 3 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: arch_mapping)
x86_64: amd64
aarch64: arm64
armv7l: armhf
i386: i386
ppc64le: ppc64le

arch: "{{ arch_mapping[ansible_architecture] | default('amd64') }}"

Check failure on line 10 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: arch)

binary_url: "https://github.com/grafana/alloy/releases/download/v{{ version }}/alloy-linux-{{ arch }}.zip"

Check failure on line 12 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: binary_url)

service_name: "alloy"

Check failure on line 14 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: service_name)

installation_dir: "/etc/alloy"
installation_dir: "/usr/local/bin"

Check failure on line 16 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: installation_dir)

environment_file: "service.env"

Check failure on line 18 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: environment_file)

config_dir: "/etc/alloy"

Check failure on line 20 in roles/alloy/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: config_dir)

config_file: "config.alloy"

Expand All @@ -25,7 +25,7 @@

service_group: "alloy"

working_dir: "/etc/alloy"
working_dir: "/var/lib/alloy"

env_file_vars: {}

Expand Down
9 changes: 9 additions & 0 deletions roles/alloy/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
Expand Down
13 changes: 2 additions & 11 deletions roles/alloy/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion roles/alloy/templates/alloy.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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() %}
Expand Down
Loading