ansible: sum over fact array
6,010
There are map
and sum
filters in Jinja:
- set_fact:
disk_size: "{{ (item.value.sectors | int) * (item.value.sectorsize | int) }}"
with_dict: "{{ ansible_devices }}"
register: disk_sizes
- debug: msg="{{ disk_sizes.results | map(attribute='ansible_facts.disk_size') | map('int') | sum(start=0) }}"
Related videos on Youtube
Author by
vijay rajah
Updated on September 18, 2022Comments
-
vijay rajah over 1 year
I want to get disk sizes of multiple disks and sum them to check if the sum of their sizes is greater than the minimum required.
We are going to use LVM to create mountpoints, we need to be able to use singe disk or multiple disks.
I'm able to get individual disk sizes using ansible facts ( ansible_devices.items.sectors|int * ansible_devices.items.sectorsize|int) using with_items
I want to sum all of these. How do I do that
-
Matt over 7 yearsHave you considered using the Python API for ansible docs.ansible.com/ansible/dev_guide/…?
-