summaryrefslogtreecommitdiff
path: root/ansible-supervision/roles/set-config-telegraf/tasks/main.yml
blob: b5f800fa05d553ac5bf16a6d4fafedaa75c59683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
- name: Telegraf repository key
  ansible.builtin.apt_key:
    url: https://repos.influxdata.com/influxdata-archive_compat.key
    state: present

- name: Telegraf repository
  ansible.builtin.apt_repository:
    repo: "deb https://repos.influxdata.com/ubuntu {{ ansible_distribution_release }} stable"
    state: present
    filename: telegraf
  register: repo_telegraf

- name: Update cache
  ansible.builtin.apt:
    update_cache: true
  when: repo_telegraf.changed

- name: Telegraf packages
  ansible.builtin.apt:
    name: telegraf
    state: present

- name: Cherche si postfix est présent
  ansible.builtin.stat:
    path: /opt/zimbra/common/sbin/mailq
  register: postfix

- name: Ajoute les groupes nécessaire à l'utilisateur telegraf
  ansible.builtin.user:
    name: telegraf
    groups: zimbra,sudo,postfix,postdrop
  when: postfix.stat.exists

- name: Ajoute les groupes nécessaire à l'utilisateur telegraf
  ansible.builtin.user:
    name: telegraf
    groups: zimbra,sudo
  when: not postfix.stat.exists

- name: Donne le droit a telegraf d'éxecuter les commandes zimbra sans pass
  community.general.sudoers:
    name: zxsuite-telegraf
    user: telegraf
    runas: zimbra
    commands:
      - /opt/zimbra/bin/*

- name: Récupération du secret de LDAP
  ansible.builtin.shell: |
    /opt/zimbra/bin/zmlocalconfig -s zimbra_ldap_password | awk '{ print $3}'
  register: zimbra_ldap_password

- name: Set fact
  ansible.builtin.set_fact:
    zimbra_ldap_password: "{{ zimbra_ldap_password.stdout }}"

- name: Installation des scripts de récupération des données zimbra
  ansible.builtin.copy:
    src: files/{{ item }}
    dest: /etc/telegraf/scripts/
    mode: '0755'
    owner: root
    group: root
  loop:
#    - zimbra_one_per_day.sh
#    - zimbra_one_per_hour.sh
     - recup_info_zimbra
  notify: Reload Telegraf
  tags:
    - shscript

- name: Installation de la configuration générale de telegraf
  ansible.builtin.template:
    src: templates/telegraf.conf.j2
    dest: /etc/telegraf/telegraf.conf
    mode: '0755'
    owner: root
    group: root
  notify: Reload Telegraf

- name: Installation de la configuration spécific zimbra pour telegraf
  ansible.builtin.template:
    src: templates/{{ item }}.j2
    dest: /etc/telegraf/telegraf.d/{{ item }}
    mode: '0644'
    owner: root
    group: root
  loop:
    - zimbra_general.conf
    - zimbra_specific.conf
  notify: Reload Telegraf