From a1c51b73c7bb15a6992a01b88b75c661c8ec09aa Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Tue, 18 Feb 2020 17:25:58 +0000 Subject: [PATCH] Use macro to avoid repetition I didn't use a for loop as the logic for omitting the comma for the final element dirties the logic. Change-Id: Id29d5deebcc5126d69a1bd8395e0df989f2081f0 --- .../roles/common/templates/fluentd.json.j2 | 46 ++++++------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/ansible/roles/common/templates/fluentd.json.j2 b/ansible/roles/common/templates/fluentd.json.j2 index fe7cdd4c04..a827dc32b2 100644 --- a/ansible/roles/common/templates/fluentd.json.j2 +++ b/ansible/roles/common/templates/fluentd.json.j2 @@ -1,6 +1,15 @@ {% set fluentd_user = fluentd_binary %} {% set fluentd_dir = '/etc/' ~ fluentd_binary %} +{%- macro config_directory(dir) -%} + { + "source": "{{ container_config_directory }}/{{ dir }}", + "dest": "{{ fluentd_dir }}/{{ dir }}", + "owner": "{{ fluentd_user }}", + "perm": "0600" + } +{%- endmacro -%} + {% if fluentd_binary == 'fluentd' %} {% set fluentd_conf = 'fluent.conf' %} {% if kolla_base_distro in ['ubuntu', 'debian'] %} @@ -22,38 +31,11 @@ "owner": "{{ fluentd_user }}", "perm": "0600" }, - {# Copy all configuration files in input/ directory to include #} - {# custom input configs. #} - { - "source": "{{ container_config_directory }}/input", - "dest": "{{ fluentd_dir }}/input", - "owner": "{{ fluentd_user }}", - "perm": "0600" - }, - {# Copy all configuration files in filter/ directory to include #} - {# custom filter configs. #} - { - "source": "{{ container_config_directory }}/filter", - "dest": "{{ fluentd_dir }}/filter", - "owner": "{{ fluentd_user }}", - "perm": "0600" - }, - {# Copy all configuration files in format/ directory to include #} - {# custom format configs. #} - { - "source": "{{ container_config_directory }}/format", - "dest": "{{ fluentd_dir }}/format", - "owner": "{{ fluentd_user }}", - "perm": "0600" - }, - {# Copy all configuration files in output/ directory to include #} - {# custom output configs. #} - { - "source": "{{ container_config_directory }}/output", - "dest": "{{ fluentd_dir }}/output", - "owner": "{{ fluentd_user }}", - "perm": "0600" - } + {# Copy all files in the following directories #} + {{ config_directory("input") }}, + {{ config_directory("filter") }}, + {{ config_directory("format") }}, + {{ config_directory("output") }} ], "permissions": [ {