2023-03-03 09:53:02 +01:00
|
|
|
---
|
|
|
|
- name: Stop grafana-agent if installed
|
|
|
|
block:
|
|
|
|
# this will fail the verify first time of installation if local binary is used
|
|
|
|
- name: Ensure grafana-agent is stopped
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: grafana-agent
|
|
|
|
enabled: true
|
|
|
|
state: stopped
|
|
|
|
rescue:
|
|
|
|
# make sure that the service isn't actually installed
|
|
|
|
- name: Get the list of services
|
|
|
|
ansible.builtin.service_facts:
|
|
|
|
|
|
|
|
- name: Verify that grafana-agent is not installed
|
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
|
|
|
- _grafana_agent_systemd_unit not in services
|
|
|
|
|
|
|
|
# these tasks are ran in both install and configure, as directories could have changed
|
2023-04-18 12:27:54 +02:00
|
|
|
- name: Configure directories
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.import_tasks: install/directories.yaml
|
|
|
|
|
|
|
|
- name: Create a symbolic link
|
|
|
|
ansible.builtin.file:
|
|
|
|
src: "{{ grafana_agent_install_dir }}/{{ grafana_agent_binary }}"
|
|
|
|
dest: "/usr/local/bin/{{ grafana_agent_binary }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
state: link
|
|
|
|
|
2023-04-18 12:27:54 +02:00
|
|
|
- name: Overwrite/Create Grafana Agent service
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: grafana-agent.service.j2
|
|
|
|
dest: "{{ _grafana_agent_systemd_dir }}/{{ _grafana_agent_systemd_unit }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
|
|
|
|
2023-04-18 12:27:54 +02:00
|
|
|
- name: Create the Service Environment file
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: EnvironmentFile.j2
|
|
|
|
dest: "{{ grafana_agent_config_dir }}/{{ grafana_agent_env_file }}"
|
|
|
|
owner: root
|
|
|
|
group: "{{ grafana_agent_user_group }}"
|
|
|
|
mode: 0640
|
|
|
|
|
2023-04-18 12:27:54 +02:00
|
|
|
- name: Create Grafana Agent config
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: config.yaml.j2
|
|
|
|
dest: "{{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}"
|
|
|
|
force: true
|
|
|
|
owner: root
|
|
|
|
group: "{{ grafana_agent_user_group }}"
|
|
|
|
mode: 0640
|
|
|
|
when: grafana_agent_provisioned_config_file | length == 0
|
|
|
|
|
2023-04-18 12:27:54 +02:00
|
|
|
- name: Copy Grafana Agent config
|
2023-03-03 09:53:02 +01:00
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "{{ grafana_agent_provisioned_config_file }}"
|
|
|
|
dest: "{{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}"
|
|
|
|
owner: root
|
|
|
|
group: "{{ grafana_agent_user_group }}"
|
|
|
|
mode: 0640
|
|
|
|
when: grafana_agent_provisioned_config_file | length > 0
|