From ae46882291088747a5aa94199b3c0a8972450efb Mon Sep 17 00:00:00 2001 From: Daniele Riccucci Date: Fri, 13 Nov 2020 20:50:32 +0100 Subject: [PATCH] Allow lists as smart_devices, fixes #15 --- templates/smartd.conf.j2 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/templates/smartd.conf.j2 b/templates/smartd.conf.j2 index 2feaebb..9b11641 100644 --- a/templates/smartd.conf.j2 +++ b/templates/smartd.conf.j2 @@ -1,6 +1,24 @@ # {{ ansible_managed }} +{% set elements = [] %} +{% set n_devices = smartd_devices | length %} +{% if smartd_devices is mapping %} + {%- set names = smartd_devices.keys() | list | d([]) %} + {%- set configs = smartd_devices.values() | list | d([]) %} + {%- for i in range(n_devices) %} + {{- elements.append({"name": names[i], "config": configs[i]}) -}} + {%- endfor %} +{% else %} + {%- set names = smartd_devices | map(attribute="name") | list | d([]) %} + {%- set configs = smartd_devices | map(attribute="config") | list | d([]) %} + {%- for i in range(n_devices) %} + {{- elements.append({"name": names[i], "config": configs[i]}) -}} + {%- endfor %} +{% endif %} + -{% for name,config in smartd_devices.items() | d([]) %} +{% for d in elements | d([]) %} +{% set name = d.name %} +{% set config = d.config %} {{- name -}} {%- if config.type|d(smartd_default_type) != 'auto' %} {{- " -d " }}{{ config.type|d(smartd_default_type) -}}