Hi all I’ve some variables scattered in my roles dirs:
fstype: [ ‘xfs’, ‘ext4’, ‘ext3’, ‘btrfs’, ‘ufs’ ] #enable check on all partition of the listed types
default_limit: { limit: 90, unit: ‘%’ }
mountpoints:
- { mount: “/”, limit: 80, unit: “%” }
- { mount: “/usr/local” } #use default limit
#mntpoints: “{{ mountpoint|default(ansible_mounts|selectattr(‘fstype’, ‘in’, fstype))|map(‘combine’, default_limit)|list }}”
mntpoints: “{{ mountpoints|selectattr(‘limit’,‘defined’)|list + mountpoints|selectattr(‘limit’,‘undefined’)|map(‘combine’,default_limit)|list if mountpoints|default()|length > 0 else ansible_mounts|selectattr(‘fstype’, ‘in’, fstype)|map(‘combine’,default_limit)|list }}”
my aim is to get a list of mount points with a space limit defined or otherwise set to a default value, if specific mounts aren’t chosen the filesystems of the specified types are yielded out…
And I got it the snippet works… but it’s really nasty, ahah I make python gigs nasty… the revenge of the dirty perl guy… anyway-
I’ve a lot of questions…
in the commented assignment the issue was that combine overwrote existent limits…
so I had to opt for the long and repetitive filter chain…
Is possible to split the long jinja2 assignment on more lines to improve readability? how?
Is there a more brilliant way to write my filter without creating a new combine filter?
In order to improve the readability I’d like to shorten the ansible_mounts hash
Is there a way to make projection (a sort of map over more fields)? Yes, I know it’s not useful, anyway I like to know if it’s possible…
Would it be better placing the logic in the template file?
thanks
Luca