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

feat: alloy installation via repository + suse support #309

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions roles/alloy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ alloy_uninstall: false
alloy_expose_port: false
alloy_download_url_rpm: "https://github.com/grafana/alloy/releases/download/v{{ alloy_version }}/alloy-{{ alloy_version }}-1.{{ __alloy_arch }}.rpm"
alloy_download_url_deb: "https://github.com/grafana/alloy/releases/download/v{{ alloy_version }}/alloy-{{ alloy_version }}-1.{{ __alloy_arch }}.deb"
alloy_install_type: "url" # url or repository
alloy_apt_signing_key_url: "https://apt.grafana.com/gpg.key"
alloy_apt_repo: "deb [signed-by=/etc/apt/trusted.gpg.d/grafana.asc] https://apt.grafana.com stable main"
alloy_rpm_signing_key_url: "https://rpm.grafana.com/gpg.key"
alloy_rpm_repo_url: "https://rpm.grafana.com"

alloy_user_groups: []
# alloy_user_groups:
Expand Down
3 changes: 3 additions & 0 deletions roles/alloy/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
state: restarted
enabled: true
when: not ansible_check_mode

- name: dnf-clean-metadata
ansible.builtin.command: "dnf clean all"
50 changes: 49 additions & 1 deletion roles/alloy/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,62 @@ dependency:
driver:
name: docker
platforms:
- name: instance
- name: alloy-rocky8
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux8}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: alloy-rocky9
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: alloy-debian11
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: alloy-debian12
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian12}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: alloy-opensuseleap15
image: "geerlingguy/docker-${MOLECULE_DISTRO:-opensuseleap15}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: alloy-ubuntu2204
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
- name: alloy-ubuntu2404
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
playbooks:
Expand Down
7 changes: 6 additions & 1 deletion roles/alloy/tasks/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Obtain the latest version from the GitHub repo
when: alloy_version == "latest"
when: alloy_version == "latest" and alloy_install_type == "url"
block:
- name: Scrape Github API endpoint to obtain latest Alloy version
ansible.builtin.uri:
Expand Down Expand Up @@ -41,6 +41,11 @@
file: setup-Debian.yml
when: ansible_facts['os_family'] == 'Debian'

- name: Include SUSE setup
ansible.builtin.include_tasks:
file: setup-Suse.yml
when: ansible_facts['os_family'] == 'Suse'

- name: Alloy systemd override
when: alloy_systemd_override | length > 0
block:
Expand Down
27 changes: 25 additions & 2 deletions roles/alloy/tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
---
- name: APT - Install Alloy
- name: APT - Install from Remote URL
ansible.builtin.apt:
deb: "{{ alloy_download_url_deb }}"
state: present
notify: restart alloy
when: __current_deployed_version.stdout is not defined or alloy_version not in __current_deployed_version.stdout
when: (__current_deployed_version.stdout is not defined or alloy_version not in __current_deployed_version.stdout) and alloy_install_type == "url"

- name: Import apt repository key
ansible.builtin.get_url:
url: "{{ alloy_apt_signing_key_url }}"
dest: "/etc/apt/trusted.gpg.d/grafana.asc"
mode: '0644'
force: true
when: alloy_install_type == "repository"

- name: Add grafana repository to sources list
ansible.builtin.apt_repository:
repo: "{{ alloy_apt_repo }}"
state: present
filename: grafana
when: alloy_install_type == "repository"

- name: APT - Install Alloy from Repository
ansible.builtin.apt:
name: alloy
state: latest
update_cache: yes
notify: restart alloy
when: alloy_install_type == "repository"
35 changes: 34 additions & 1 deletion roles/alloy/tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,37 @@
state: present
disable_gpg_check: true
notify: restart alloy
when: __current_deployed_version.stdout is not defined or alloy_version not in __current_deployed_version.stdout
when: (__current_deployed_version.stdout is not defined or alloy_version not in __current_deployed_version.stdout) and alloy_install_type == "url"

- name: Install required packages for repository installation
ansible.builtin.package:
name: "{{ item }}"
state: present
loop: "{{ __alloy_required_packages }}"
when: alloy_install_type == "repository"

- name: Import grafana signing key
ansible.builtin.rpm_key:
state: present
key: "{{ alloy_rpm_signing_key_url }}"
when: alloy_install_type == "repository"

- name: Add grafana dnf repository
ansible.builtin.yum_repository:
name: grafana
description: "Grafana Repository"
baseurl: "{{ alloy_rpm_repo_url }}"
repo_gpgcheck: true
enabled: true
gpgcheck: true
gpgkey: "{{ alloy_rpm_signing_key_url }}"
sslverify: true
sslcacert: "/etc/pki/tls/certs/ca-bundle.crt"
when: alloy_install_type == "repository"

- name: DNF - Install Alloy from Repository
ansible.builtin.dnf:
name: alloy
state: latest
notify: restart alloy
when: alloy_install_type == "repository"
34 changes: 34 additions & 0 deletions roles/alloy/tasks/setup-Suse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: ZYPPER - Install Alloy from remote URL
ansible.builtin.zypper:
name: "{{ alloy_download_url_rpm }}"
state: present
disable_gpg_check: true
notify: restart alloy
when: (__current_deployed_version.stdout is not defined or alloy_version not in __current_deployed_version.stdout) and alloy_install_type == "url"

- name: Install required packages for repository installation
ansible.builtin.package:
name: "{{ item }}"
state: present
loop: "{{ __alloy_required_packages }}"
when: alloy_install_type == "repository"

- name: Import grafana signing key
ansible.builtin.rpm_key:
state: present
key: "{{ alloy_rpm_signing_key_url }}"
when: alloy_install_type == "repository"

- name: Add grafana zypper repository
community.general.zypper_repository:
name: grafana
repo: "{{ alloy_rpm_repo_url }}"
state: present
when: alloy_install_type == "repository"

- name: ZYPPER - Install Alloy from Repository
community.general.zypper:
name: alloy
state: present
update_cache: true
28 changes: 27 additions & 1 deletion roles/alloy/tasks/uninstall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
state: stopped
ignore_errors: true

- name: Uninstall Alloy rpm package
- name: Uninstall Alloy dnf package
ansible.builtin.dnf:
name: "alloy"
state: absent
Expand All @@ -19,6 +19,12 @@
purge: true
when: ansible_facts['os_family'] == 'Debian'

- name: Uninstall Alloy zypper package
community.general.zypper:
name: alloy
state: absent
when: ansible_facts['os_family'] == 'Suse'

- name: Ensure that Alloy firewalld rule is not present - tcp port {{ __alloy_server_http_listen_port }}
ansible.posix.firewalld: # noqa ignore-errors
immediate: true
Expand Down Expand Up @@ -50,3 +56,23 @@
ansible.builtin.group:
name: "alloy"
state: absent

- name: Remove dnf repository (and clean up left-over metadata)
ansible.builtin.yum_repository:
name: grafana
state: absent
notify: dnf-clean-metadata
when: ansible_facts['os_family'] in ['RedHat', 'Rocky']

- name: Remove deb repository
ansible.builtin.file:
path: /etc/apt/sources.list.d/grafana.list
state: absent
when: ansible_facts['os_family'] == 'Debian'

- name: Remove zypper repository
community.general.zypper_repository:
name: grafana
repo: 'https://rpm.grafana.com'
state: absent
when: ansible_facts['os_family'] == 'Suse'
3 changes: 3 additions & 0 deletions roles/alloy/vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
---
__alloy_env_file: "/etc/sysconfig/alloy"
__alloy_required_packages:
- gpg

4 changes: 4 additions & 0 deletions roles/alloy/vars/Suse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
__alloy_env_file: "/etc/sysconfig/alloy"
__alloy_required_packages:
- gpg2