Hello everyone ![]()
Since my colleagues, friends, and I primarily work on Linux hosts, we often need to extract or verify the data collected by sar.
While exploring the existing Ansible modules in ansible.builtin and community.general, I noticed that there is currently no facts module capable of extracting this data.
To address this, I am developing a new module called sar_facts, which retrieves data collected by sar and generates a structured dictionary within ansible_facts.
Current selectable data categories:
CPULoad AverageMemorySwapNetworkDisk
Available parameters:
| parameter | type | required | choices | default | description | 
|---|---|---|---|---|---|
| type | str | true | CPU, Load, Memory, Swap, Network, Disk | ND | collection category | 
| date_start | str | false | ND | None | collection start date | 
| date_end | str | false | ND | None | collection end date | 
| average | bool | false | true,false | false | get only average data | 
| partition | bool | false | true,false | false | get Disk data by partition | 
The module produces a dictionary with the following structure:
    "ansible_facts.sar_data": {
        "TYPE": {
            "DATE": {
                "TIME": {
                    "key": "value"
                }
            }
        }
    }
DATE and TIME are repeated for each collected day and hour.
Here’s an example of a task to extract disk data from 06/02/2025, to 07/02/2025, in partition mode:
    - name: collect disk data
      sar_facts:
        type: "Disk"
        partition: true
        date_start: "06/02/2025"
        date_end: "07/02/2025"
The ease of data extraction comes at the cost of the effort required to filter it and obtain specific information. ![]()
For example, to retrieve the list of await values for the specific volume centos-root, you would need to do the following:
    - name: Extract all await values for centos-root
      set_fact:
        root_await: >-
          {{ ansible_facts.sar_data.Disk
            | dict2items
            | map(attribute='value')
            | map('dict2items')
            | list | sum(start=[])
            | selectattr('value', 'defined')
            | map(attribute='value')
            | list | sum(start=[])
            | selectattr('DEV', 'equalto', 'centos-root')
            | map(attribute='await')
            | list
          }}
This module is still a work in progress and has not yet been published on GitHub.
The question is: would it actually be useful to Ansible users?
Would it be worth adding to ansible-core or community.general?