From b37a30a760ccb91d58c9c37be22e2eed08437133 Mon Sep 17 00:00:00 2001 From: Duong Ha-Quang Date: Mon, 5 Feb 2018 16:09:30 +0700 Subject: [PATCH] Add policy.yaml support for blazar role Follow up of https://review.openstack.org/#/c/454752 Change-Id: I20a3677b30ef6133fc3456b0449464a6a88d1581 Closes-Bug: #1747375 --- ansible/roles/blazar/tasks/config.yml | 32 +++++++++++++------ .../roles/blazar/templates/blazar-api.json.j2 | 11 +++---- .../blazar/templates/blazar-manager.json.j2 | 11 +++---- ansible/roles/blazar/templates/blazar.conf.j2 | 5 +++ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/ansible/roles/blazar/tasks/config.yml b/ansible/roles/blazar/tasks/config.yml index 472de1b7ba..26a23ebd9a 100644 --- a/ansible/roles/blazar/tasks/config.yml +++ b/ansible/roles/blazar/tasks/config.yml @@ -9,6 +9,23 @@ - item.value.enabled | bool with_dict: "{{ blazar_services }}" +- name: Check if policies shall be overwritten + local_action: stat path="{{ item }}" + run_once: True + register: blazar_policy + with_first_found: + - files: "{{ supported_policy_format_list }}" + paths: + - "{{ node_custom_config }}/blazar/" + skip: true + +- name: Set blazar policy file + set_fact: + blazar_policy_file: "{{ blazar_policy.results.0.stat.path | basename }}" + blazar_policy_file_path: "{{ blazar_policy.results.0.stat.path }}" + when: + - blazar_policy.results + - name: Copying over config.json files for services template: src: "{{ item.key }}.json.j2" @@ -42,19 +59,14 @@ - Restart blazar-api container - Restart blazar-manager container -- name: Check if policies shall be overwritten - local_action: stat path="{{ node_custom_config }}/blazar/policy.json" - register: blazar_policy - -- name: Copying over existing policy.json +- name: Copying over existing policy file template: - src: "{{ node_custom_config }}/blazar/policy.json" - dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" - register: blazar_policy_jsons + src: "{{ blazar_policy_file_path }}" + dest: "{{ node_config_directory }}/{{ item.key }}/{{ blazar_policy_file }}" + register: blazar_policy_overwriting when: - - blazar_policy.stat.exists + - blazar_policy_file is defined - inventory_hostname in groups[item.value.group] - - item.value.enabled | bool with_dict: "{{ blazar_services }}" notify: - Restart blazar-api container diff --git a/ansible/roles/blazar/templates/blazar-api.json.j2 b/ansible/roles/blazar/templates/blazar-api.json.j2 index 12468e54ba..02a8e07591 100644 --- a/ansible/roles/blazar/templates/blazar-api.json.j2 +++ b/ansible/roles/blazar/templates/blazar-api.json.j2 @@ -6,14 +6,13 @@ "dest": "/etc/blazar/blazar.conf", "owner": "blazar", "perm": "0600" - }, + }{% if blazar_policy_file is defined %}, { - "source": "{{ container_config_directory }}/policy.json", - "dest": "/etc/blazar/policy.json", + "source": "{{ container_config_directory }}/{{ blazar_policy_file }}", + "dest": "/etc/blazar/{{ blazar_policy_file }}", "owner": "blazar", - "perm": "0600", - "optional": true - } + "perm": "0600" + }{% endif %} ], "permissions": [ { diff --git a/ansible/roles/blazar/templates/blazar-manager.json.j2 b/ansible/roles/blazar/templates/blazar-manager.json.j2 index 6bd74e752b..8dda3afbd4 100644 --- a/ansible/roles/blazar/templates/blazar-manager.json.j2 +++ b/ansible/roles/blazar/templates/blazar-manager.json.j2 @@ -6,14 +6,13 @@ "dest": "/etc/blazar/blazar.conf", "owner": "blazar", "perm": "0600" - }, + }{% if blazar_policy_file is defined %}, { - "source": "{{ container_config_directory }}/policy.json", - "dest": "/etc/blazar/policy.json", + "source": "{{ container_config_directory }}/{{ blazar_policy_file }}", + "dest": "/etc/blazar/{{ blazar_policy_file }}", "owner": "blazar", - "perm": "0600", - "optional": true - } + "perm": "0600" + }{% endif %} ], "permissions": [ { diff --git a/ansible/roles/blazar/templates/blazar.conf.j2 b/ansible/roles/blazar/templates/blazar.conf.j2 index e62171f9f7..53380195ec 100644 --- a/ansible/roles/blazar/templates/blazar.conf.j2 +++ b/ansible/roles/blazar/templates/blazar.conf.j2 @@ -56,3 +56,8 @@ topics = notifications {% else %} driver = noop {% endif %} + +{% if blazar_policy_file is defined %} +[oslo_policy] +policy_file = {{ blazar_policy_file }} +{% endif %}