Skip to content

Allow disable for calculating size for win_stat #384

@stonesbg

Description

@stonesbg
SUMMARY

Allow for an opt out flag to be passed as part of win_stat to disable the calculation of size this can be used for both directory and for file.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

win_stat

ADDITIONAL INFORMATION

Right now, win_stat by default includes the size of a directory. This is fine in most cases but when trying to check for an existence of a drive letter or for a folder with a lot of data in it win_stat will just hang as it tries to calculate this information.

https://github.com/ansible-collections/ansible.windows/blob/main/plugins/modules/win_stat.ps1#L130-L149

It would be nice if there was an opt out option where you could set a flag to ignore directory size calculation. This could be as simple as passing a get_size bool operator to disable the calculation of size. Default could be yes/true as to not break backwards compatibility.

- name: Obtain information about a directory
  ansible.windows.win_stat:
    path: C:\
    get_size: no
  register: file_info

Feature request came about from the scenario where I was checking the existence of a directory. This directory is ephemeral drive so on reboot this drive would get deleted and re-added as part of AWS or GCP. Once created the drive is created the SQL Server tempdb get created on it at 5GB per file. This could be between 4 and 8 files. On initial run this would work first time but on subsequent run the win_stat would hang for hours.

The second instance was when checking the existing of docker folder exists. This data directory was getting moved between c:\ to d:\ and the test was validating that the drive was created in the new location. On initial runs this was fun as now containers had yet been pulled down but as time went on more and more windows container layers were pulled and stored. This directory ending up growing to excess of 30GB and win_stat would hang.

I locally tested by removing the size calculating and that fixed the problem so right now workaround is to not use win_stat and do it with PowerShell for any folders that potentially will grow in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions