Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds max_matches parameter to ansible.builtin.find #83153

Open
wants to merge 8 commits into
base: devel
Choose a base branch
from

Conversation

colin-nolan
Copy link
Contributor

SUMMARY

ansible.builtin.find currently looks for matches in all non-filtered files. When there is a very big file system in the search scope, and/or an expensive search is made (e.g. based off whole file contents), the operation can be very expensive.

This PR adds the ability for the user to limit the number of matches that are made. Use cases that would benefit/be enabled with this functionality include:

  • Determining if there are > n matching files in a directory.
  • Finding the first directory in a nested tree with any files.
  • Discovering where the file with matching content is (stopping once found!).
ISSUE TYPE
  • Feature Pull Request
ADDITIONAL INFORMATION

Try the module using:

# Can't run module in place due to import issues caused by other modules in directory
cp lib/ansible/modules/find.py /tmp/find.py && python /tmp/find.py <<EOF
{
    "ANSIBLE_MODULE_ARGS": {
        "paths": "/var/log",
        "file_type": "file",
        "contains": "wally",
        "read_whole_file": true,
        "patterns": "^.*\\\.log$",
        "use_regex": true,
        "recurse": true,
        "max_matches": 1
    }
}
EOF

@ansibot ansibot added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. module This issue/PR relates to a module. labels Apr 28, 2024
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Apr 30, 2024
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 7, 2024
@colin-nolan colin-nolan closed this May 8, 2024
@colin-nolan colin-nolan reopened this May 8, 2024
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 8, 2024
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request. module This issue/PR relates to a module. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants