|
1 | 1 | # SPDX-License-Identifier: MIT |
2 | 2 | --- |
3 | | -- name: Ensure ansible_facts used by role |
4 | | - setup: |
5 | | - gather_subset: "{{ __metrics_required_facts_subsets }}" |
6 | | - when: __metrics_required_facts | |
7 | | - difference(ansible_facts.keys() | list) | length > 0 |
8 | | - |
9 | | -- name: Determine if system is booted with systemd |
10 | | - when: __metrics_is_booted is not defined |
11 | | - block: |
12 | | - - name: Run systemctl |
13 | | - # noqa command-instead-of-module |
14 | | - command: systemctl is-system-running |
15 | | - register: __is_system_running |
16 | | - changed_when: false |
17 | | - failed_when: false |
18 | | - |
19 | | - - name: Require installed systemd |
20 | | - fail: |
21 | | - msg: "Error: This role requires systemd to be installed." |
22 | | - when: '"No such file or directory" in __is_system_running.msg | d("")' |
23 | | - |
24 | | - - name: Set flag to indicate that systemd runtime operations are available |
25 | | - set_fact: |
26 | | - # see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output |
27 | | - __metrics_is_booted: "{{ __is_system_running.stdout != 'offline' }}" |
| 3 | +- name: Ensure facts and vars used by role are set |
| 4 | + include_tasks: set_vars.yml |
28 | 5 |
|
29 | 6 | - name: Add Elasticsearch to metrics domain list |
30 | 7 | set_fact: |
|
137 | 114 | name: "{{ role_path }}/roles/pcp" |
138 | 115 | when: metrics_provider == 'pcp' |
139 | 116 |
|
140 | | -- name: Setup metric graphing service. |
| 117 | +- name: Manage metrics graphing service |
141 | 118 | vars: |
142 | | - grafana_metrics_provider: "{{ metrics_provider }}" |
143 | | - include_role: |
144 | | - # noqa role-name[path] |
145 | | - name: "{{ role_path }}/roles/grafana" |
| 119 | + grafana_cert: "{{ __metrics_grafana_cert_dir + '/' + metrics_grafana_certificates.0.name + '.crt' |
| 120 | + if metrics_grafana_certificates | length > 0 |
| 121 | + else metrics_grafana_cert if metrics_grafana_cert.startswith('/') |
| 122 | + else __metrics_grafana_cert_dir + '/' + metrics_grafana_cert if metrics_grafana_cert | length > 0 |
| 123 | + else __metrics_grafana_cert_dir + '/' + metrics_grafana_cert_src | basename |
| 124 | + if metrics_grafana_cert_src | length > 0 |
| 125 | + else '' }}" |
| 126 | + grafana_private_key: "{{ __metrics_grafana_private_key_dir + '/' + metrics_grafana_certificates.0.name + '.key' |
| 127 | + if metrics_grafana_certificates | length > 0 |
| 128 | + else metrics_grafana_private_key if metrics_grafana_private_key.startswith('/') |
| 129 | + else __metrics_grafana_private_key_dir + '/' + metrics_grafana_private_key if metrics_grafana_private_key | length > 0 |
| 130 | + else __metrics_grafana_private_key_dir + '/' + metrics_grafana_private_key_src | basename |
| 131 | + if metrics_grafana_private_key_src | length > 0 |
| 132 | + else '' }}" |
146 | 133 | when: metrics_graph_service | bool |
| 134 | + block: |
| 135 | + - name: Create certificates using the certificate role |
| 136 | + when: |
| 137 | + - metrics_grafana_certificates | length > 0 |
| 138 | + - ansible_facts['os_family'] == 'RedHat' |
| 139 | + block: |
| 140 | + - name: Check the OS version for self-sign |
| 141 | + when: |
| 142 | + - (ansible_facts['distribution_version'] | int == 7 and |
| 143 | + metrics_grafana_certificates.0.ca == 'self-sign') |
| 144 | + fail: |
| 145 | + msg: >- |
| 146 | + Creating a self-signed certificate is not supported on |
| 147 | + {{ ansible_facts['distribution'] }}-{{ |
| 148 | + ansible_facts['distribution_version'] }} |
| 149 | +
|
| 150 | + - name: Create certificates using the certificate role |
| 151 | + include_role: |
| 152 | + name: fedora.linux_system_roles.certificate |
| 153 | + vars: |
| 154 | + certificate_requests: "{{ metrics_grafana_certificates }}" |
| 155 | + |
| 156 | + - name: Copy grafana cert |
| 157 | + copy: |
| 158 | + src: "{{ metrics_grafana_cert_src }}" |
| 159 | + dest: "{{ grafana_cert }}" |
| 160 | + mode: "0644" |
| 161 | + owner: root |
| 162 | + group: root |
| 163 | + when: metrics_grafana_cert_src | length > 0 |
| 164 | + |
| 165 | + - name: Copy grafana private key |
| 166 | + copy: |
| 167 | + src: "{{ metrics_grafana_private_key_src }}" |
| 168 | + dest: "{{ grafana_private_key }}" |
| 169 | + mode: "0600" |
| 170 | + owner: root |
| 171 | + group: root |
| 172 | + when: metrics_grafana_private_key_src | length > 0 |
| 173 | + no_log: true |
| 174 | + |
| 175 | + - name: Setup metric graphing service. |
| 176 | + vars: |
| 177 | + grafana_metrics_provider: "{{ metrics_provider }}" |
| 178 | + include_role: |
| 179 | + # noqa role-name[path] |
| 180 | + name: "{{ role_path }}/roles/grafana" |
| 181 | + when: metrics_graph_service | bool |
147 | 182 |
|
148 | 183 | - name: Configure firewall |
149 | 184 | include_tasks: firewall.yml |
|
0 commit comments