|
| 1 | +--- |
| 2 | +- name: Ensure monitoring directory exists |
| 3 | + file: |
| 4 | + path: "/opt/oci-hpc/monitoring" |
| 5 | + state: directory |
| 6 | + owner: opc |
| 7 | + group: opc |
| 8 | + |
| 9 | +- name: Copy files |
| 10 | + become: true |
| 11 | + copy: |
| 12 | + src: '{{ item }}' |
| 13 | + dest: '/opt/oci-hpc/monitoring/{{ item }}' |
| 14 | + force: no |
| 15 | + owner: opc |
| 16 | + group: opc |
| 17 | + with_items: |
| 18 | + - dashboard.json |
| 19 | + - initial.sql |
| 20 | + |
| 21 | +- name: Copy scripts |
| 22 | + become: true |
| 23 | + copy: |
| 24 | + src: '{{ item }}' |
| 25 | + dest: '/opt/oci-hpc/monitoring/{{ item }}' |
| 26 | + force: no |
| 27 | + owner: opc |
| 28 | + group: opc |
| 29 | + mode: 0755 |
| 30 | + with_items: |
| 31 | + - initial.sh |
| 32 | + - monitor_oci.sh |
| 33 | + - monitor_slurm.sh |
| 34 | + |
| 35 | +- name: Generate env file |
| 36 | + template: |
| 37 | + src: env.j2 |
| 38 | + dest: /opt/oci-hpc/monitoring/env |
| 39 | + |
| 40 | +- name: add grafana repository |
| 41 | + become: true |
| 42 | + yum_repository: |
| 43 | + name: grafana |
| 44 | + description: grafana |
| 45 | + baseurl: https://packages.grafana.com/oss/rpm |
| 46 | + repo_gpgcheck: 1 |
| 47 | + enabled: 1 |
| 48 | + gpgcheck: 1 |
| 49 | + gpgkey: https://packages.grafana.com/gpg.key |
| 50 | + sslverify: 1 |
| 51 | + sslcacert: /etc/pki/tls/certs/ca-bundle.crt |
| 52 | + |
| 53 | +- name: install grafana |
| 54 | + become: true |
| 55 | + yum: |
| 56 | + name: grafana |
| 57 | + state: latest |
| 58 | + |
| 59 | +- name: start grafana |
| 60 | + become: true |
| 61 | + service: |
| 62 | + name: grafana-server |
| 63 | + state: restarted |
| 64 | + enabled: true |
| 65 | + |
| 66 | +- name: Ensure grafana key directory exists |
| 67 | + file: |
| 68 | + path: "/etc/opt/oci-hpc/passwords/grafana" |
| 69 | + state: directory |
| 70 | + delegate_to: localhost |
| 71 | + |
| 72 | +- name: Check api key list |
| 73 | + uri: |
| 74 | + url: "{{ grafana_api_url }}/api/auth/keys" |
| 75 | + user: "{{ grafana_security.admin_user }}" |
| 76 | + password: "{{ grafana_security.admin_password }}" |
| 77 | + force_basic_auth: true |
| 78 | + return_content: true |
| 79 | + no_log: false |
| 80 | + register: existing_api_keys |
| 81 | + |
| 82 | +- name: install EL7 mysql release file |
| 83 | + become: true |
| 84 | + yum: |
| 85 | + name: https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm |
| 86 | + |
| 87 | +- name: Ensure GPG key is installed for the repository |
| 88 | + become: true |
| 89 | + ansible.builtin.rpm_key: |
| 90 | + state: present |
| 91 | + key: https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 |
| 92 | + |
| 93 | +- name: install mysql-shell |
| 94 | + become: true |
| 95 | + yum: |
| 96 | + name: mysql-shell |
| 97 | + update_cache: yes |
| 98 | + |
| 99 | +- name: install mysql connector |
| 100 | + become: true |
| 101 | + pip: |
| 102 | + name: mysql-connector-python |
| 103 | + executable: pip-3 |
| 104 | + |
| 105 | +- name: Get root password from /etc/opt/oci-hpc/passwords |
| 106 | + set_fact: |
| 107 | + mysql_root_pwd: "{{ lookup('password', |
| 108 | + '/etc/opt/oci-hpc/passwords/mysql/root.txt |
| 109 | + chars=ascii_letters,digits') }}" |
| 110 | + when: not autoscaling_mysql_service | bool |
| 111 | + |
| 112 | +- name: Get root password from configuration |
| 113 | + set_fact: |
| 114 | + mysql_root_pwd: "{{ admin_password }}" |
| 115 | + when: autoscaling_mysql_service | bool |
| 116 | + |
| 117 | +- name: Generate mysql_service_initial file |
| 118 | + template: |
| 119 | + src: mysql_service_initial.j2 |
| 120 | + dest: /opt/oci-hpc/monitoring/mysql_service_initial.sql |
| 121 | + when: autoscaling_mysql_service | bool |
| 122 | + |
| 123 | +- name: Create database 'cluster_log' |
| 124 | + mysql_db: |
| 125 | + login_user: "{{ admin_username }}" |
| 126 | + login_password: "{{ mysql_root_pwd }}" |
| 127 | + name: cluster_log |
| 128 | + state: present |
| 129 | + when: not autoscaling_mysql_service | bool |
| 130 | + |
| 131 | +- name: Create database user with name 'logger' and password |
| 132 | + mysql_user: |
| 133 | + login_user: "{{ admin_username }}" |
| 134 | + login_password: "{{ mysql_root_pwd }}" |
| 135 | + name: logger |
| 136 | + password: Monitor2021! |
| 137 | + priv: cluster_log.*:SELECT,INSERT,UPDATE,DELETE |
| 138 | + state: present |
| 139 | + when: not autoscaling_mysql_service | bool |
| 140 | + |
| 141 | +- name: Create initial DB |
| 142 | + shell: "source /opt/oci-hpc/monitoring/env; mysqlsh {{ admin_username }}@{{ monitoring_mysql_ip }} -p{{ mysql_root_pwd }} --sql --file /opt/oci-hpc/monitoring/mysql_service_initial.sql" |
| 143 | + ignore_errors: yes |
| 144 | + when: autoscaling_mysql_service | bool |
| 145 | + |
| 146 | +- name: Create initial DB |
| 147 | + shell: "source /opt/oci-hpc/monitoring/env; mysqlsh {{ admin_username }}@{{ monitoring_mysql_ip }} -p{{ mysql_root_pwd }} --sql --file /opt/oci-hpc/monitoring/initial.sql" |
| 148 | + ignore_errors: yes |
| 149 | + |
| 150 | +- name: Monitoring activated |
| 151 | + shell: "echo OK >> /opt/oci-hpc/monitoring/activated" |
| 152 | + |
| 153 | +- name: Create mysql datasource |
| 154 | + grafana_datasource: |
| 155 | + name: "autoscaling" |
| 156 | + grafana_url: "{{ grafana_api_url }}" |
| 157 | + grafana_user: "{{ grafana_security.admin_user }}" |
| 158 | + grafana_password: "{{ grafana_security.admin_password }}" |
| 159 | + org_id: "1" |
| 160 | + ds_type: "mysql" |
| 161 | + ds_url: "{{ monitoring_mysql_ip }}:3306" |
| 162 | + database: "cluster_log" |
| 163 | + password: "Monitor2021!" |
| 164 | + user: "logger" |
| 165 | + ignore_errors: yes |
| 166 | + |
| 167 | +# - name: Import grafana dashboards through API |
| 168 | +# uri: |
| 169 | +# url: "{{ grafana_api_url }}/api/dashboards/db" |
| 170 | +# user: "{{ grafana_security.admin_user }}" |
| 171 | +# password: "{{ grafana_security.admin_password }}" |
| 172 | +# force_basic_auth: true |
| 173 | +# method: POST |
| 174 | +# body_format: json |
| 175 | +# body: > |
| 176 | +# { |
| 177 | +# "dashboard": {{ lookup("file", item) }}, |
| 178 | +# "overwrite": true, |
| 179 | +# "message": "Updated by ansible" |
| 180 | +# } |
| 181 | +# no_log: false |
| 182 | +# with_fileglob: |
| 183 | +# - files/dashboard.json |
| 184 | +# ignore_errors: yes |
| 185 | + |
| 186 | +#- name: Create influxdb datasource |
| 187 | +# grafana_datasource: |
| 188 | +# name: "InfluxDB" |
| 189 | +# grafana_url: "{{ grafana_api_url }}" |
| 190 | +# grafana_user: "{{ grafana_security.admin_user }}" |
| 191 | +# grafana_password: "{{ grafana_security.admin_password }}" |
| 192 | +# org_id: "1" |
| 193 | +# ds_type: "influxdb" |
| 194 | +# ds_url: "http://localhost:8086" |
| 195 | +# database: "telegraf" |
| 196 | +# time_interval: ">10s" |
| 197 | + |
| 198 | +#- name: Import grafana dashboards through API |
| 199 | +# uri: |
| 200 | +# url: "{{ grafana_api_url }}/api/dashboards/db" |
| 201 | +# user: "{{ grafana_security.admin_user }}" |
| 202 | +# password: "{{ grafana_security.admin_password }}" |
| 203 | +# force_basic_auth: true |
| 204 | +# method: POST |
| 205 | +# body_format: json |
| 206 | +# body: > |
| 207 | +# { |
| 208 | +# "dashboard": {{ lookup("file", item) }}, |
| 209 | +# "overwrite": true, |
| 210 | +# "message": "Updated by ansible" |
| 211 | +# } |
| 212 | +# no_log: false |
| 213 | +# with_fileglob: |
| 214 | +# - files/cluster.json |
| 215 | + |
| 216 | +#- name: Import Grafana dashboard foo |
| 217 | +# community.grafana.grafana_dashboard: |
| 218 | +# grafana_url: "{{ grafana_api_url }}" |
| 219 | +# grafana_user: "{{ grafana_security.admin_user }}" |
| 220 | +# grafana_password: "{{ grafana_security.admin_password }}" |
| 221 | +# state: present |
| 222 | +# message: Updated by ansible |
| 223 | +# overwrite: yes |
| 224 | +# path: files/cluster.json |
0 commit comments