Filter loop lists instead of conditionally run them
Filtering loops should execute faster and do not iterate over elements that we don't need. Change-Id: Iee2e706c50b59679f48afbd6f067922887154e5c
This commit is contained in:
parent
2ce606c40a
commit
a0fb5a6df2
@ -56,8 +56,7 @@
|
|||||||
owner: "{{ item.systemd_user_name | default(systemd_user_name) }}"
|
owner: "{{ item.systemd_user_name | default(systemd_user_name) }}"
|
||||||
group: "{{ item.systemd_group_name | default(systemd_group_name) }}"
|
group: "{{ item.systemd_group_name | default(systemd_group_name) }}"
|
||||||
mode: "02755"
|
mode: "02755"
|
||||||
when: "'systemd_overrides' in item"
|
loop: "{{ systemd_services | rejectattr('systemd_overrides', 'undefined') }}"
|
||||||
loop: "{{ systemd_services }}"
|
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ loop_label | to_json }}"
|
label: "{{ loop_label | to_json }}"
|
||||||
vars:
|
vars:
|
||||||
@ -88,7 +87,7 @@
|
|||||||
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service"
|
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service"
|
||||||
config_overrides: "{{ item.config_overrides | default(systemd_service_config_overrides) }}"
|
config_overrides: "{{ item.config_overrides | default(systemd_service_config_overrides) }}"
|
||||||
config_type: "ini"
|
config_type: "ini"
|
||||||
loop: "{{ systemd_services }}"
|
loop: "{{ systemd_services | rejectattr('systemd_overrides_only', 'true') }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ loop_label | to_json }}"
|
label: "{{ loop_label | to_json }}"
|
||||||
vars:
|
vars:
|
||||||
@ -97,7 +96,6 @@
|
|||||||
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service"
|
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service"
|
||||||
config_overrides: "{{ item.config_overrides | default(systemd_service_config_overrides) }}"
|
config_overrides: "{{ item.config_overrides | default(systemd_service_config_overrides) }}"
|
||||||
config_type: "ini"
|
config_type: "ini"
|
||||||
when: not (item.systemd_overrides_only | default(False) | bool)
|
|
||||||
notify:
|
notify:
|
||||||
- systemd service changed
|
- systemd service changed
|
||||||
register: systemd_services_result
|
register: systemd_services_result
|
||||||
@ -108,14 +106,13 @@
|
|||||||
template:
|
template:
|
||||||
src: "systemd-service-overrides.j2"
|
src: "systemd-service-overrides.j2"
|
||||||
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service.d/override.conf"
|
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service.d/override.conf"
|
||||||
loop: "{{ systemd_services }}"
|
loop: "{{ systemd_services | rejectattr('systemd_overrides', 'undefined') }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ loop_label | to_json }}"
|
label: "{{ loop_label | to_json }}"
|
||||||
vars:
|
vars:
|
||||||
loop_label:
|
loop_label:
|
||||||
src: "systemd-service-overrides.j2"
|
src: "systemd-service-overrides.j2"
|
||||||
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service.d/override.conf"
|
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service.d/override.conf"
|
||||||
when: "'systemd_overrides' in item"
|
|
||||||
notify:
|
notify:
|
||||||
- systemd service changed
|
- systemd service changed
|
||||||
register: systemd_override_result
|
register: systemd_override_result
|
||||||
@ -129,9 +126,7 @@
|
|||||||
mode: "0644"
|
mode: "0644"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
when:
|
loop: "{{ systemd_services | selectattr('timer', 'defined') }}"
|
||||||
- item.timer is defined
|
|
||||||
loop: "{{ systemd_services }}"
|
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ loop_label | to_json }}"
|
label: "{{ loop_label | to_json }}"
|
||||||
vars:
|
vars:
|
||||||
|
Loading…
Reference in New Issue
Block a user