ansible: Install and configure promtail
authorKienan Stewart <kstewart@efficios.com>
Tue, 15 Oct 2024 17:44:52 +0000 (13:44 -0400)
committerKienan Stewart <kstewart@efficios.com>
Tue, 15 Oct 2024 17:44:52 +0000 (13:44 -0400)
Change-Id: Ia0625da7547412fdb41abdfd31036d0a378c939e
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
automation/ansible/group_vars/hosts.yml
automation/ansible/group_vars/node_amd64.yml
automation/ansible/group_vars/node_arm64.yml [new file with mode: 0644]
automation/ansible/roles/common/defaults/main.yml
automation/ansible/roles/common/files/grafana.gpg [new file with mode: 0644]
automation/ansible/roles/common/tasks/setup-Debian.yml
automation/ansible/roles/common/templates/promtail.config.yml.j2 [new file with mode: 0644]

index 9b5fabc0de95f82b8e673d0b00b8f28d259d0c89..793cd347522937ad7e29470a99dad1c15844c3cc 100644 (file)
@@ -1,3 +1,4 @@
 ---
+common_install_promtail: true
 libvirt_extra_users:
   - jenkins
index 83ea4e9e4b442fc86c7cb6b94874b91a9cd047b5..5bcd79ae3796d3639210e2b78b445b69e401a969 100644 (file)
@@ -1,2 +1,4 @@
 ---
+
+common_install_promtail: true
 lttng_modules_checkout_repo: true
diff --git a/automation/ansible/group_vars/node_arm64.yml b/automation/ansible/group_vars/node_arm64.yml
new file mode 100644 (file)
index 0000000..085cef5
--- /dev/null
@@ -0,0 +1,3 @@
+---
+
+common_install_promtail: true
index ef157af5936f56d80f4c04743158c91bbca10c63..321fbfc881a1483415c4db5cba489c478689c004 100644 (file)
@@ -3,3 +3,6 @@ unattended_upgrades: true
 common_certificate_cert_path_prefix: '/etc/ssl/certs'
 common_certificate_key_path_prefix: '/etc/ssl/private'
 common_certificate_deploy_combined_pem: true
+
+common_install_promtail: false
+common_promtail_client: 'http://graph01:3500/loki/api/v1/push'
diff --git a/automation/ansible/roles/common/files/grafana.gpg b/automation/ansible/roles/common/files/grafana.gpg
new file mode 100644 (file)
index 0000000..d199581
Binary files /dev/null and b/automation/ansible/roles/common/files/grafana.gpg differ
index b71ca6e27a838705d063bb8cafc088416d06e586..70ab6e502373dc9b0ea5953f017e9c656e969212 100644 (file)
         file: '/etc/gitconfig'
         name: 'http.version'
         value: 'HTTP/1.1'
+
+- when: common_install_promtail
+  block:
+    - name: Add apt source
+      block:
+        - name: Install signing key
+          ansible.builtin.copy:
+            dest: /etc/apt/keyrings/grafana.gpg
+            src: grafana.gpg
+          register: signing_key
+        - name: Add apt source
+          ansible.builtin.apt_repository:
+            filename: grafana
+            repo: 'deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main'
+          register: apt_source
+        - name: Apt update
+          when: signing_key.changed or apt_source.changed
+          ansible.builtin.apt:
+            update_cache: true
+    - name: Install promtail
+      ansible.builtin.package:
+        name: ['promtail']
+    - name: Allow promtail user to read logs
+      ansible.builtin.user:
+        name: promtail
+        append: true
+        groups:
+          - systemd-journal
+    - name: Configure promtail
+      ansible.builtin.template:
+        src: promtail.config.yml.j2
+        dest: '/etc/promtail/config.yml'
+        owner: 'root'
+        group: 'root'
+        mode: '0644'
+      register: promtail_configuration
+    - name: Manage promtail service
+      ansible.builtin.service:
+        name: 'promtail'
+        enabled: true
+        state: "{{promtail_configuration.changed|ternary('restarted', 'started')}}"
diff --git a/automation/ansible/roles/common/templates/promtail.config.yml.j2 b/automation/ansible/roles/common/templates/promtail.config.yml.j2
new file mode 100644 (file)
index 0000000..0282f37
--- /dev/null
@@ -0,0 +1,19 @@
+clients:
+-   url: {{common_promtail_client}}
+positions:
+    filename: /tmp/positions.yaml
+scrape_configs:
+-   job_name: journal
+    journal:
+        json: true
+        labels:
+            host: "{{inventory_hostname}}"
+            job: systemd-journal
+            ci_role: "{{(inventory_hostname in group_names)|ternary('host', 'ci-node')}}"
+        max_age: 1h
+    relabel_configs:
+    -   source_labels:
+        - __journal__systemd_unit
+        target_label: unit
+server:
+    disable: true
This page took 0.025963 seconds and 4 git commands to generate.