aboutsummaryrefslogtreecommitdiff
path: root/roles/services/monitoring/promtail
diff options
context:
space:
mode:
Diffstat (limited to 'roles/services/monitoring/promtail')
-rw-r--r--roles/services/monitoring/promtail/handlers/main.yml39
-rw-r--r--roles/services/monitoring/promtail/tasks/main.yml151
2 files changed, 190 insertions, 0 deletions
diff --git a/roles/services/monitoring/promtail/handlers/main.yml b/roles/services/monitoring/promtail/handlers/main.yml
new file mode 100644
index 0000000..97ea7d3
--- /dev/null
+++ b/roles/services/monitoring/promtail/handlers/main.yml
@@ -0,0 +1,39 @@
1- name: update repos - debian
2 apt:
3 update_cache: yes
4
5- name: update repos - fedora
6 dnf:
7 name: "*"
8 state: latest
9
10- name: build loki-docker-driver plugin for private repo
11 become: yes
12 become_user: "{{ docker_username }}"
13 environment:
14 LOKI_DOCKER_DRIVER: "{{ docker_registry_url }}/{{ docker_registry_username }}/loki-docker-driver"
15 community.general.make:
16 chdir: "{{ docker_home }}/plugins/loki"
17 target: docker-driver-push
18
19- name: restart rootless docker
20 become: yes
21 become_user: "{{ docker_username }}"
22 systemd:
23 name: docker
24 enabled: yes
25 state: restarted
26 scope: user
27 environment:
28 XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}"
29
30- name: restart docker
31 service:
32 name: docker
33 state: restarted
34
35- name: restart promtail
36 when: promtail_config.changed
37 service:
38 name: promtail
39 state: restarted
diff --git a/roles/services/monitoring/promtail/tasks/main.yml b/roles/services/monitoring/promtail/tasks/main.yml
new file mode 100644
index 0000000..f8b28cc
--- /dev/null
+++ b/roles/services/monitoring/promtail/tasks/main.yml
@@ -0,0 +1,151 @@
1- name: install extrepo
2 when: ansible_facts['distribution'] == 'Debian'
3 package:
4 name: extrepo
5 state: latest
6
7- name: add grafana repo | debian
8 when: ansible_facts['distribution'] == 'Debian'
9 register: result
10 changed_when: result.stdout | regex_search("skipped") | bool
11 notify: update repos - debian
12 command:
13 cmd: extrepo enable grafana
14 creates: /etc/apt/sources.list.d/extrepo_grafana.sources
15
16- meta: flush_handlers
17
18- name: update grafana extrepo data | debian
19 when: ansible_facts['distribution'] == 'Debian'
20 changed_when: false
21 command:
22 cmd: extrepo update grafana
23
24- name: add Grafana repo | fedora
25 when: ansible_facts['distribution'] == 'Fedora'
26 notify: update repos - fedora
27 yum_repository:
28 name: grafana
29 file: grafna
30 description: "Grafana OSS Repo"
31 baseurl: "https://rpm.grafana.com"
32 repo_gpgcheck: yes
33 enabled: yes
34 gpgcheck: yes
35 gpgkey: https://rpm.grafana.com/gpg.key
36 sslverify: yes
37 sslcacert: /etc/pki/tls/certs/ca-bundle.crt
38 exclude: "*beta*"
39
40- name: install promtail
41 package:
42 name: promtail
43 state: latest
44
45- name: add promtail to adm group for log access (debian)
46 when: ansible_facts['distribution'] == 'Debian'
47 user:
48 name: promtail
49 groups: adm
50 append: yes
51
52- name: add promtail to systemd-journal group for journal access
53 user:
54 name: promtail
55 groups: systemd-journal
56 append: yes
57
58- name: create docker plugin directory
59 when: "'docker_hosts' in group_names"
60 become: yes
61 become_user: "{{ docker_username }}"
62 file:
63 path: "{{ docker_home }}/plugins"
64 state: directory
65 owner: "{{ docker_username }}"
66 group: "{{ docker_username }}"
67 mode: "0755"
68
69- name: clone loki repo
70 when: "'docker_hosts' in group_names"
71 become: yes
72 become_user: "{{ docker_username }}"
73 git:
74 repo: "{{ loki_repo }}"
75 dest: "{{ docker_home }}/plugins/loki"
76 version: "{{ loki_version }}"
77 register: repo
78 notify: build loki-docker-driver plugin for private repo
79
80- meta: flush_handlers
81
82- name: login to docker registry
83 when: "'docker_hosts' in group_names"
84 become: yes
85 become_user: "{{ docker_username }}"
86 environment:
87 XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}"
88 docker_login:
89 docker_host: "unix://run/user/{{ docker_uid }}/docker.sock"
90 registry_url: "{{ docker_registry_url }}"
91 username: "{{ docker_registry_username }}"
92 password: "{{ docker_registry_password }}"
93
94# docker driver rootless
95
96- name: enable loki-docker-driver plugin
97 when: "'docker_hosts' in group_names"
98 become: yes
99 become_user: "{{ docker_username }}"
100 notify: restart rootless docker
101 community.docker.docker_plugin:
102 plugin_name: "{{ docker_registry_url }}/{{ docker_registry_username }}/loki-docker-driver:main"
103 state: enable
104 docker_host: "unix://run/user/{{ docker_uid }}/docker.sock"
105 alias: loki
106
107- name: deploy docker config
108 when: "'docker_hosts' in group_names"
109 notify: restart rootless docker
110 copy:
111 src: "{{ docker_config }}"
112 dest: "{{ docker_home }}/.config/docker/daemon.json"
113 owner: "{{ docker_username }}"
114 group: "{{ docker_username }}"
115 mode: '0644'
116
117# docker driver root
118
119- name: enable loki-docker-driver plugin
120 when: "'docker_hosts' in group_names"
121 notify: restart docker
122 community.docker.docker_plugin:
123 plugin_name: "{{ docker_registry_url }}/{{ docker_registry_username }}/loki-docker-driver:main"
124 state: enable
125 alias: loki
126
127- name: deploy docker config
128 when: "'docker_hosts' in group_names"
129 notify: restart docker
130 copy:
131 src: "{{ docker_config }}"
132 dest: /etc/docker/daemon.json
133 owner: root
134 group: root
135 mode: '0644'
136
137- name: deploy promtail configuration
138 notify: restart promtail
139 copy:
140 src: "{{ promtail_config }}"
141 dest: /etc/promtail/config.yml
142 owner: root
143 group: root
144 mode: '0644'
145
146- name: enable promtail
147 systemd:
148 daemon_reload: yes
149 enabled: yes
150 masked: no
151 name: promtail