ANSIBLE: Looping over complex dict using several variables

I want to be able to determine the average size of a particular list of directories over a number of hosts. I start on the hosts by finding the directories i want, evaluating their size and putting the results in a nice dict:

  - name: find log dirs
    shell: "find / -type d -name 'log' 2>/dev/null | sort"
    register: log_list

  - name: evaluate dir sizes
    shell: "du -sk {{ item }} | awk '{ print $1 }'"
    register: folder_size 
    loop : "{{ log_list.stdout_lines }}"

  - name: build dict
    set_fact:
      folder_info: "{{ folder_info|default({}) | combine({item.item: {'path': item.item, 'size': item.stdout|int}}) }}"
    loop: "{{ folder_size.results }}"

Back on the Ansible controller i put all those dicts together in a nice big dict, and also put together a list of dirs:

  - name: gather folder info
    set_fact:
      all_dirs: "{{ all_dirs|default([]) + hostvars[item].dir_list|unique }}"
      all_folder_info: "{{ all_folder_info|default({}) | combine({hostvars[item].inventory_hostname:hostvars[item].folder_info}) }}"
    loop: "{{ groups['backoffice'] }}"

Debugging all_folder_info gives me something like this:

TASK [debug] *******************************************************************
ok: [localhost] => {
    "all_folder_info": {
        "some.host.com": {
            "/some/directory/": {
                "path": "/some/directory",
                "size": 220
            },
            "/some/other/directory": {
                "path": "/some/other/directory",
                "size": 8
            },
            "/some/third/directory": {
                "path": "/some/third/directory",
                "size": 319404
            }
        },

I now need to iterate over this huge dict to extract the info i want and do math on it, but i'm stuck. I tried zipping like this, that Ansible says can't template:

  - name: debug
    debug: 
      var: (all_folder_info[item.0].[item.1].size | sum) / (all_folder_info[item.0].[item.1].size | length)
    loop: "{{ groups['backoffice']|zip_longest(all_dirs|unique)|list }}"

This seems to at best just put the two lists into key:value pairs. What am i doing wrong ?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum