From: Kienan Stewart Date: Tue, 15 Oct 2024 17:44:52 +0000 (-0400) Subject: ansible: Install and configure promtail X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1399ce511371d664ce1b78030897919bfc9d585d;p=lttng-ci.git ansible: Install and configure promtail Change-Id: Ia0625da7547412fdb41abdfd31036d0a378c939e Signed-off-by: Kienan Stewart --- diff --git a/automation/ansible/group_vars/hosts.yml b/automation/ansible/group_vars/hosts.yml index 9b5fabc..793cd34 100644 --- a/automation/ansible/group_vars/hosts.yml +++ b/automation/ansible/group_vars/hosts.yml @@ -1,3 +1,4 @@ --- +common_install_promtail: true libvirt_extra_users: - jenkins diff --git a/automation/ansible/group_vars/node_amd64.yml b/automation/ansible/group_vars/node_amd64.yml index 83ea4e9..5bcd79a 100644 --- a/automation/ansible/group_vars/node_amd64.yml +++ b/automation/ansible/group_vars/node_amd64.yml @@ -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 index 0000000..085cef5 --- /dev/null +++ b/automation/ansible/group_vars/node_arm64.yml @@ -0,0 +1,3 @@ +--- + +common_install_promtail: true diff --git a/automation/ansible/roles/common/defaults/main.yml b/automation/ansible/roles/common/defaults/main.yml index ef157af..321fbfc 100644 --- a/automation/ansible/roles/common/defaults/main.yml +++ b/automation/ansible/roles/common/defaults/main.yml @@ -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 index 0000000..d199581 Binary files /dev/null and b/automation/ansible/roles/common/files/grafana.gpg differ diff --git a/automation/ansible/roles/common/tasks/setup-Debian.yml b/automation/ansible/roles/common/tasks/setup-Debian.yml index b71ca6e..70ab6e5 100644 --- a/automation/ansible/roles/common/tasks/setup-Debian.yml +++ b/automation/ansible/roles/common/tasks/setup-Debian.yml @@ -95,3 +95,44 @@ 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 index 0000000..0282f37 --- /dev/null +++ b/automation/ansible/roles/common/templates/promtail.config.yml.j2 @@ -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