From ccdecf061ebd39e1fb78c5f370613afb0392294e Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Tue, 1 Jun 2021 19:19:07 +0200 Subject: [PATCH] Make the monitoring stack ports configurable for each daemon According to [1] the monitoring stack daemons are able to bind on the specified {ip}:{port}. This change turns the previously defined monitoring items into a dict where the name of the daemon and the port can be specified (the ports are supposed to come from the tht parameters). In addition, we need to make sure that the port parameter is evaluated as an int, otherwise cephadm fails when the spec is applied. For this reason a new 'normalize_spec' function is introduced, with the purpose of analyzing the provided payload and make sure the port parameters are expressed as int. This is required due to the fact that the ansible option 'ANSIBLE_JINJA2_NATIVE=True' [2], which is supposed to enable this feature at tripleo-ansible level is missing, but it's a constraint we wouldn't like to introduce. [1] https://github.com/ceph/ceph/pull/41444 [2] https://docs.ansible.com/ansible/latest/reference_appendices/config.html#envvar-ANSIBLE_JINJA2_NATIVE Change-Id: I3f1d0205f2228d59c5e8bc6b33084c64974c2a2b --- .../ansible_plugins/module_utils/ceph_spec.py | 13 ++++++++++++- .../roles/tripleo_cephadm/tasks/monitoring.yaml | 14 ++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/module_utils/ceph_spec.py b/tripleo_ansible/ansible_plugins/module_utils/ceph_spec.py index a976c2edb..8296ed21b 100644 --- a/tripleo_ansible/ansible_plugins/module_utils/ceph_spec.py +++ b/tripleo_ansible/ansible_plugins/module_utils/ceph_spec.py @@ -208,7 +208,7 @@ class CephDaemonSpec(object): # append the spec if provided if len(self.spec.keys()) > 0: if self.validate_keys(self.spec.keys(), ALLOWED_SPEC_KEYS): - sp = {'spec': self.filter_spec(self.spec)} + sp = {'spec': self.normalize_spec(self.filter_spec(self.spec))} else: raise Exception("Fatal: the spec should be composed by only allowed keywords") @@ -216,6 +216,17 @@ class CephDaemonSpec(object): spec_template = {**spec_template, **ntw, **self.extra, **pl, **sp} return spec_template + def normalize_spec(self, spec): + ''' + For each spec key we need to make sure + that ports are evaluated as int, otherwise + cephadm fails when the spec is applied. + ''' + for k, v in spec.items(): + if 'port' in k: + spec[k] = int(v) + return spec + def filter_spec(self, spec): return {k: v for k, v in spec.items() if v} diff --git a/tripleo_ansible/roles/tripleo_cephadm/tasks/monitoring.yaml b/tripleo_ansible/roles/tripleo_cephadm/tasks/monitoring.yaml index fa728388f..83b732028 100644 --- a/tripleo_ansible/roles/tripleo_cephadm/tasks/monitoring.yaml +++ b/tripleo_ansible/roles/tripleo_cephadm/tasks/monitoring.yaml @@ -63,20 +63,22 @@ - name: Create the monitoring stack Daemon spec definition become: true ceph_mkspec: - service_type: "{{ item }}" - service_id: "{{ item }}" - service_name: "{{ item }}" + service_type: "{{ item.daemon }}" + service_id: "{{ item.daemon }}" + service_name: "{{ item.daemon }}" apply: true hosts: "{{ _hosts | unique }}" render_path: "{{ tripleo_cephadm_spec_home }}" networks: "{{ tripleo_cephadm_monitoring_address_block }}" + spec: + port: "{{ item.port }}" environment: CEPH_CONTAINER_IMAGE: "{{ tripleo_cephadm_container_ns + '/' + tripleo_cephadm_container_image + ':' + tripleo_cephadm_container_tag }}" CEPH_CONTAINER_BINARY: "{{ tripleo_cephadm_container_cli }}" with_items: - - "alertmanager" - - "prometheus" - - "grafana" + - {"daemon": "grafana", "port": "{{ tripleo_cephadm_grafana_port | default(3100) }}"} + - {"daemon": "prometheus", "port": "{{ tripleo_cephadm_prometheus_port | default(9092) }}"} + - {"daemon": "alertmanager", "port": "{{ tripleo_cephadm_alertmanager_port | default(9094) }}"} when: tripleo_cephadm_dashboard_enabled | bool - include_tasks: dashboard/dashboard.yaml