From f0e19ba6476937350115ff2189449e0b00e5ded5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Fri, 3 May 2019 13:38:51 -0300 Subject: [PATCH] Method to override the default ceilometer meters.yaml via Kolla-ansible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to what we did here: https://review.opendev.org/#/c/655276 but, for ceilometer/data/meters.d/meters.yaml file. The idea is to create a method for operators to manage custom meters YAML files via Kolla-ansible. To do that, we enable them (operators) to use a folder called by default "meters.d" in their local ceilometer configurations, where all of the custom meters YAML files will be read from. If this folder exist and has YAML files in it, we copy them for the default "/etc/ceilometer/meters.d" path in the containers. We do not inject things in the container though. We copy the files for the control node, and then we map them via ceilometer*.json container configuration files. Change-Id: I712edcf39bfdb64887e25437f0aff30a45a829dd Signed-off-by: Rafael Weingärtner --- ansible/roles/ceilometer/defaults/main.yml | 2 + ansible/roles/ceilometer/tasks/config.yml | 48 ++++++++++++++++++- .../templates/ceilometer-central.json.j2 | 6 +++ .../templates/ceilometer-compute.json.j2 | 6 +++ .../templates/ceilometer-ipmi.json.j2 | 6 +++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/ansible/roles/ceilometer/defaults/main.yml b/ansible/roles/ceilometer/defaults/main.yml index 05cfe730e6..4d26e625fb 100644 --- a/ansible/roles/ceilometer/defaults/main.yml +++ b/ansible/roles/ceilometer/defaults/main.yml @@ -99,3 +99,5 @@ ceilometer_git_repository: "{{ kolla_dev_repos_git }}/ceilometer" ceilometer_dev_repos_pull: "{{ kolla_dev_repos_pull }}" ceilometer_dev_mode: "{{ kolla_dev_mode }}" ceilometer_source_version: "{{ kolla_source_version }}" + +ceilometer_custom_meters_local_folder: "meters.d" diff --git a/ansible/roles/ceilometer/tasks/config.yml b/ansible/roles/ceilometer/tasks/config.yml index 335e61d5ed..fab16d667c 100644 --- a/ansible/roles/ceilometer/tasks/config.yml +++ b/ansible/roles/ceilometer/tasks/config.yml @@ -12,7 +12,53 @@ - item.value.enabled | bool with_dict: "{{ ceilometer_services }}" -- name: Check custom polling.yaml exists +- name: Check if the folder for custom meter definitions exist + local_action: stat path="{{ node_custom_config }}/ceilometer/{{ ceilometer_custom_meters_local_folder }}" + register: ceilometer_custom_meters_folder + +- name: Set variable that indicates if we have a folder for custom meter YAML files + set_fact: + custom_meter_folder_exist: "{{ ceilometer_custom_meters_folder.stat.exists and ceilometer_custom_meters_folder.stat.isdir }}" + +- name: Find all *.yaml files in custom meter definitions folder (if the folder exist) + local_action: find paths="{{ node_custom_config }}/ceilometer/{{ ceilometer_custom_meters_local_folder }}" patterns="*.yaml" + register: ceilometer_custom_meters_folder_found_files + when: custom_meter_folder_exist + +- name: Set the variable that control the copy of custom meter definitions + set_fact: + should_copy_custom_meter_definitions: "{{ custom_meter_folder_exist and ceilometer_custom_meters_folder_found_files.matched > 0 }}" + +- name: Create default folder for custom meter definitions + file: + path: "{{ node_config_directory }}/{{ item.key }}/meters.d" + state: "directory" + owner: "{{ config_owner_user }}" + group: "{{ config_owner_group }}" + mode: "0770" + become: true + with_dict: "{{ ceilometer_services }}" + when: + - should_copy_custom_meter_definitions + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + +- name: Copying custom meter definitions to Ceilometer + copy: + src: "{{ node_custom_config }}/ceilometer/{{ ceilometer_custom_meters_local_folder }}/" + dest: "{{ node_config_directory }}/{{ item.key }}/meters.d" + force: True + mode: "0660" + become: true + when: + - should_copy_custom_meter_definitions + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ ceilometer_services }}" + notify: + - "Restart {{ item.key }} container" + +- name: Check if custom polling.yaml exists local_action: stat path="{{ node_custom_config }}/ceilometer/polling.yaml" register: ceilometer_polling_file diff --git a/ansible/roles/ceilometer/templates/ceilometer-central.json.j2 b/ansible/roles/ceilometer/templates/ceilometer-central.json.j2 index 6cf4810abb..609dfac8cf 100644 --- a/ansible/roles/ceilometer/templates/ceilometer-central.json.j2 +++ b/ansible/roles/ceilometer/templates/ceilometer-central.json.j2 @@ -18,6 +18,12 @@ "dest": "/etc/ceilometer/{{ ceilometer_policy_file }}", "owner": "ceilometer", "perm": "0600" + }{% endif %}{% if should_copy_custom_meter_definitions %}, + { + "source": "{{ container_config_directory }}/meters.d", + "dest": "/etc/ceilometer/meters.d", + "owner": "ceilometer", + "perm": "0700" }{% endif %}, { "source": "{{ container_config_directory }}/pipeline.yaml", diff --git a/ansible/roles/ceilometer/templates/ceilometer-compute.json.j2 b/ansible/roles/ceilometer/templates/ceilometer-compute.json.j2 index 19e8e04725..c341962dc6 100644 --- a/ansible/roles/ceilometer/templates/ceilometer-compute.json.j2 +++ b/ansible/roles/ceilometer/templates/ceilometer-compute.json.j2 @@ -18,6 +18,12 @@ "dest": "/etc/ceilometer/{{ ceilometer_policy_file }}", "owner": "ceilometer", "perm": "0600" + }{% endif %}{% if should_copy_custom_meter_definitions %}, + { + "source": "{{ container_config_directory }}/meters.d", + "dest": "/etc/ceilometer/meters.d", + "owner": "ceilometer", + "perm": "0700" }{% endif %}, { "source": "{{ container_config_directory }}/pipeline.yaml", diff --git a/ansible/roles/ceilometer/templates/ceilometer-ipmi.json.j2 b/ansible/roles/ceilometer/templates/ceilometer-ipmi.json.j2 index 3a643cf03d..2fa317064d 100644 --- a/ansible/roles/ceilometer/templates/ceilometer-ipmi.json.j2 +++ b/ansible/roles/ceilometer/templates/ceilometer-ipmi.json.j2 @@ -18,6 +18,12 @@ "dest": "/etc/ceilometer/{{ ceilometer_policy_file }}", "owner": "ceilometer", "perm": "0600" + }{% endif %}{% if should_copy_custom_meter_definitions %}, + { + "source": "{{ container_config_directory }}/meters.d", + "dest": "/etc/ceilometer/meters.d", + "owner": "ceilometer", + "perm": "0700" }{% endif %} ], "permissions": [