|
| 1 | +- name: Run setup playbook |
| 2 | + ansible.builtin.import_playbook: setup.yaml |
| 3 | + vars: |
| 4 | + host: telemetry |
| 5 | + |
| 6 | +- name: Run elixir playbook |
| 7 | + ansible.builtin.import_playbook: elixir.yaml # fix! |
| 8 | + vars: |
| 9 | + host: telemetry |
| 10 | + |
| 11 | +- name: Setup Telemetry |
| 12 | + hosts: telemetry |
| 13 | + become: true |
| 14 | + |
| 15 | + vars: |
| 16 | + prometheus_version: "2.53.2" |
| 17 | + ansible_ssh_user: admin |
| 18 | + |
| 19 | + tasks: |
| 20 | + # install prometeus |
| 21 | + # add config template to set server's IP (ini file) |
| 22 | + # grafana |
| 23 | + # config |
| 24 | + # OpenTelemetry Collector |
| 25 | + # install Jaeger |
| 26 | + # install Cassandra |
| 27 | + # install postgres |
| 28 | + # install aligned Telemetry api |
| 29 | + # install caddy |
| 30 | + # add template for caddyfile for grafana (public) and Jaeger (tailscale) |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + apt: |
| 34 | + name: |
| 35 | + - apt-transport-https |
| 36 | + - software-properties-common |
| 37 | + - wget |
| 38 | + state: present |
| 39 | + update_cache: yes |
| 40 | + |
| 41 | + - name: Create keyrings directory for Grafana |
| 42 | + file: |
| 43 | + path: /etc/apt/keyrings |
| 44 | + state: directory |
| 45 | + mode: '0755' |
| 46 | + |
| 47 | + - name: Download and install Grafana GPG key |
| 48 | + shell: |
| 49 | + cmd: wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor -o /etc/apt/keyrings/grafana.gpg |
| 50 | + creates: /etc/apt/keyrings/grafana.gpg |
| 51 | + |
| 52 | + - name: Add Grafana stable repository |
| 53 | + shell: |
| 54 | + cmd: echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list |
| 55 | + creates: /etc/apt/sources.list.d/grafana.list |
| 56 | + |
| 57 | + - name: Update apt cache and install Grafana |
| 58 | + apt: |
| 59 | + name: grafana |
| 60 | + state: present |
| 61 | + update_cache: yes |
| 62 | + |
| 63 | + - name: Check if Prometheus is installed |
| 64 | + stat: |
| 65 | + path: /usr/local/bin/prometheus |
| 66 | + register: prometheus_exists |
| 67 | + |
| 68 | + - name: Create Prometheus group |
| 69 | + when: not prometheus_exists.stat.exists |
| 70 | + group: |
| 71 | + name: prometheus |
| 72 | + system: yes |
| 73 | + |
| 74 | + - name: Create Prometheus user |
| 75 | + when: not prometheus_exists.stat.exists |
| 76 | + user: |
| 77 | + name: prometheus |
| 78 | + group: prometheus |
| 79 | + shell: /sbin/nologin |
| 80 | + system: yes |
| 81 | + |
| 82 | + - name: Download Prometheus |
| 83 | + when: not prometheus_exists.stat.exists |
| 84 | + get_url: |
| 85 | + url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz" |
| 86 | + dest: "/tmp/prometheus-{{ prometheus_version }}.tar.gz" |
| 87 | + mode: '0644' |
| 88 | + |
| 89 | + - name: Extract Prometheus |
| 90 | + when: not prometheus_exists.stat.exists |
| 91 | + unarchive: |
| 92 | + src: "/tmp/prometheus-{{ prometheus_version }}.tar.gz" |
| 93 | + dest: /tmp/ |
| 94 | + remote_src: yes |
| 95 | + |
| 96 | + - name: Create Prometheus directories |
| 97 | + when: not prometheus_exists.stat.exists |
| 98 | + file: |
| 99 | + path: "{{ item }}" |
| 100 | + state: directory |
| 101 | + owner: prometheus |
| 102 | + group: prometheus |
| 103 | + mode: '0755' |
| 104 | + loop: |
| 105 | + - /etc/prometheus |
| 106 | + - /var/lib/prometheus |
| 107 | + |
| 108 | + - name: Move Prometheus |
| 109 | + when: not prometheus_exists.stat.exists |
| 110 | + copy: |
| 111 | + remote_src: true |
| 112 | + src: "{{ item.src }}" |
| 113 | + dest: "{{ item.dest }}" |
| 114 | + owner: prometheus |
| 115 | + group: prometheus |
| 116 | + mode: '0755' |
| 117 | + with_items: |
| 118 | + - { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/prometheus", dest: "/usr/local/bin/prometheus" } |
| 119 | + - { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/promtool", dest: "/usr/local/bin/promtool" } |
| 120 | + |
| 121 | + - name: Move Prometheus configuration and consoles |
| 122 | + when: not prometheus_exists.stat.exists |
| 123 | + copy: |
| 124 | + remote_src: true |
| 125 | + src: "{{ item.src }}" |
| 126 | + dest: "{{ item.dest }}" |
| 127 | + owner: prometheus |
| 128 | + group: prometheus |
| 129 | + mode: '0755' |
| 130 | + with_items: |
| 131 | + - { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/consoles", dest: "/etc/prometheus/consoles" } |
| 132 | + - { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/console_libraries", dest: "/etc/prometheus/console_libraries" } |
| 133 | + - { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/prometheus.yml", dest: "/etc/prometheus/prometheus.yml" } |
| 134 | + |
| 135 | + - name: Clean up Prometheus tar and extracted directory |
| 136 | + when: not prometheus_exists.stat.exists |
| 137 | + file: |
| 138 | + path: "{{ item }}" |
| 139 | + state: absent |
| 140 | + loop: |
| 141 | + - "/tmp/prometheus-{{ prometheus_version }}.tar.gz" |
| 142 | + - "/tmp/prometheus-{{ prometheus_version }}.linux-amd64" |
| 143 | + |
| 144 | + - name: Add prometheus config file |
| 145 | + template: |
| 146 | + src: prometheus/prometheus.yaml.j2 |
| 147 | + dest: /etc/prometheus/prometheus.yml |
| 148 | + vars: |
| 149 | + aligned_aggregator_prometheus_ip: "{{ lookup('ini', 'aligned_aggregator_prometheus_ip', file='ini/config-telemetry.ini') }}" |
| 150 | + aligned_operator_prometheus_ip: "{{ lookup('ini', 'aligned_operator_prometheus_ip', file='ini/config-telemetry.ini') }}" |
| 151 | + aligned_batcher_prometheus_ip: "{{ lookup('ini', 'aligned_batcher_prometheus_ip', file='ini/config-telemetry.ini') }}" |
| 152 | + aligned_tracker_prometheus_ip: "{{ lookup('ini', 'aligned_tracker_prometheus_ip', file='ini/config-telemetry.ini') }}" |
| 153 | + |
| 154 | + - name: Add grafana config file |
| 155 | + template: |
| 156 | + src: grafana.ini.j21 |
| 157 | + dest: /etc/grafana/grafana.ini |
| 158 | + |
| 159 | + - name: Add Caddy repository to sources list |
| 160 | + become: true |
| 161 | + apt_repository: |
| 162 | + repo: |
| 163 | + "deb https://dl.cloudsmith.io/public/caddy/stable/deb/debian |
| 164 | + any-version main" |
| 165 | + state: present |
| 166 | + filename: caddy-stable |
| 167 | + vars: |
| 168 | + ansible_ssh_user: "{{ admin_user }}" |
| 169 | + |
| 170 | + - name: Add Caddy src repository to sources list |
| 171 | + become: true |
| 172 | + apt_repository: |
| 173 | + repo: |
| 174 | + "deb-src https://dl.cloudsmith.io/public/caddy/stable/deb/debian |
| 175 | + any-version main" |
| 176 | + state: present |
| 177 | + filename: caddy-stable |
| 178 | + vars: |
| 179 | + ansible_ssh_user: "{{ admin_user }}" |
| 180 | + |
| 181 | + - name: Install Caddy |
| 182 | + become: true |
| 183 | + apt: |
| 184 | + update_cache: yes |
| 185 | + name: caddy |
| 186 | + state: present |
| 187 | + vars: |
| 188 | + ansible_ssh_user: "{{ admin_user }}" |
| 189 | + |
| 190 | + - name: Add caddyfile config |
| 191 | + become: true |
| 192 | + template: |
| 193 | + src: caddy/Caddyfile.telemetry.j2 |
| 194 | + dest: /etc/caddy/Caddyfile |
| 195 | + vars: |
| 196 | + telemetry_api_url: "{{ lookup('ini', 'telemetry_api_url', file='ini/config-telemetry.ini') }}" |
| 197 | + |
| 198 | + handlers: |
| 199 | + - name: Restart Grafana |
| 200 | + service: |
| 201 | + name: grafana-server |
| 202 | + state: restarted |
0 commit comments