Delete based on directory size

I have been looking for a module for something similar to the du command. I would like to have a play that looks at the log directory to detect if it's a certian size or larger and if so find the sub folders with gbs of data and remove or tar that data up.

So far I am not finding that and parsing the return of the du command is not is not somethig I am having luck with.

Has anyone tried to do something similar? Have any ideas or pointers for me?

Does this help?

I created a directory structure with four files:

$ find /tmp/dirsize/ -ls | cut -c 18- drwxrwxr-x 5 dan dan 100 May 11 14:59 /tmp/dirsize/ drwxrwxr-x 2 dan dan 60 May 11 15:00 /tmp/dirsize/d3 -rw-rw-r-- 1 dan dan 5242880 May 11 15:00 /tmp/dirsize/d3/5M.file drwxrwxr-x 2 dan dan 60 May 11 15:00 /tmp/dirsize/d2 -rw-rw-r-- 1 dan dan 3145728 May 11 15:00 /tmp/dirsize/d2/3M.file drwxrwxr-x 2 dan dan 80 May 11 15:00 /tmp/dirsize/d1 -rw-rw-r-- 1 dan dan 3145728 May 11 15:00 /tmp/dirsize/d1/3M.file -rw-rw-r-- 1 dan dan 6291456 May 11 14:59 /tmp/dirsize/d1/6M.file

Then using this playbook:

`

You can use the 'find' module and register the results:

ansible -m find -a 'path=~/ size=200k file_type=directory' localhost