From 5e30aa98d95eb60ee192f13fd40fff343fb657ea Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Mon, 17 Apr 2017 16:30:41 -0700 Subject: [PATCH] Filter services dictionary per host To greatly reduce the amount of log noise from skipped tasks, set a var in the role that filters the 'nova_services' dict to one that only contains services relevant for each host. Change-Id: I17650de0ce516e3ad855e8c4bc41f48cf310b828 --- tasks/nova_init_common.yml | 5 +---- tasks/nova_init_systemd.yml | 25 +++++-------------------- vars/main.yml | 10 ++++++++++ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/tasks/nova_init_common.yml b/tasks/nova_init_common.yml index d31de03f..2ff6d4f1 100644 --- a/tasks/nova_init_common.yml +++ b/tasks/nova_init_common.yml @@ -22,9 +22,6 @@ name: "{{ item.value.service_name }}" enabled: "yes" state: "started" - with_dict: "{{ nova_services }}" - when: - - inventory_hostname in groups[item.value.group] - - "{{ item.value.condition | default(true) }}" + with_dict: "{{ filtered_nova_services }}" notify: - Restart nova services diff --git a/tasks/nova_init_systemd.yml b/tasks/nova_init_systemd.yml index 2775bfe3..099ebf5e 100644 --- a/tasks/nova_init_systemd.yml +++ b/tasks/nova_init_systemd.yml @@ -20,10 +20,7 @@ owner: "{{ nova_system_user_name }}" group: "{{ nova_system_group_name }}" mode: "02755" - with_dict: "{{ nova_services }}" - when: - - inventory_hostname in groups[item.value.group] - - "{{ item.value.condition | default(true) }}" + with_dict: "{{ filtered_nova_services }}" - name: Create TEMP lock dir file: @@ -32,10 +29,7 @@ owner: "{{ nova_system_user_name }}" group: "{{ nova_system_group_name }}" mode: "02755" - with_dict: "{{ nova_services }}" - when: - - inventory_hostname in groups[item.value.group] - - "{{ item.value.condition | default(true) }}" + with_dict: "{{ filtered_nova_services }}" # TODO(mgariepy): # Remove this in Pike as it only needed to handle upgrades @@ -44,10 +38,7 @@ file: path: "/etc/tmpfiles.d/{{ item.value.service_name }}.conf" state: absent - with_dict: "{{ nova_services }}" - when: - - inventory_hostname in groups[item.value.group] - - "{{ item.value.condition | default(true) }}" + with_dict: "{{ filtered_nova_services }}" - name: Create tmpfiles.d entry template: @@ -56,10 +47,7 @@ mode: "0644" owner: "root" group: "root" - with_dict: "{{ nova_services }}" - when: - - inventory_hostname in groups[item.value.group] - - "{{ item.value.condition | default(true) }}" + with_dict: "{{ filtered_nova_services }}" - name: Place the systemd init script config_template: @@ -70,9 +58,6 @@ group: "root" config_overrides: "{{ item.value.init_config_overrides }}" config_type: "ini" - with_dict: "{{ nova_services }}" - when: - - inventory_hostname in groups[item.value.group] - - "{{ item.value.condition | default(true) }}" + with_dict: "{{ filtered_nova_services }}" notify: - Restart nova services diff --git a/vars/main.yml b/vars/main.yml index 3d659281..07ddd9d3 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,3 +28,13 @@ nova_packages_list: enabled: "{{ 'nova_compute' in group_names and nova_virt_type == 'powervm' }}" - packages: "{{ nova_nginx_distro_packages }}" enabled: "{{ 'nova_api_placement' in group_names }}" + +filtered_nova_services: > + {%- set services = nova_services.copy() %} + {%- for key,value in nova_services.items() %} + {%- if value.group not in group_names or + (value.condition is defined and not value.condition) %} + {%- set _ = services.pop(key) %} + {%- endif %} + {%- endfor %} + {{- services -}}