How to Delete Only Files Inside a Directory with Ansible?
I’m going to show you a live demo with some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible How to Delete Only Files Inside a Directory
- Return a list of files based on specific criteria
Today we’re talking about the Ansible module `
The full name is `
ansible.builtin.find`, which means that is part of the collection included in the `
ansible-core` builtin collection.
This module returns a list of files based on specific criteria using the `find` popular Unix command.
- paths string — List of paths of directories to search
- hidden boolean — no/yes
- recurse boolean — recursively descend into the directory looking for files
- file_type string — file/directory/any/link
The most important parameters of the `
find` module for this use case.
The mandatory parameter `
paths` specify the list of paths of directories to search.
You could include hidden files with the `
As well as recurse in any directory under the main path with the `recurse` parameter.
Another useful parameter is `
file_type`, defaults to `
file` but you could filter for `
link` or `
any` filesystem object type.