I'd like to know if there's an Ansible module other than command that will give me a list of files (recursive search) containing a pattern?
On Unix I'd do
find . -type f -exec grep -l pattern {} \;
The result would be a list of files I'd iterate to change a value with another value
You can use the find module to do this. The contains parameter accepts a regex to search for file content:
- name: Find files
find:
paths: /var/log
contains: pattern
register: found_files
The result of the find modules contains the attributes files, with a list of the matched files, and matched, with the number of matched files. You can store the result by using the register attribute on the find command (found_files above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With