Ansible find files only if contains particular string
I need a small help in writing an ansible playbook. I have written the below till now which is listing all files with config basically. but I need to filter out the files which are basically .git/config
- hosts: all
connection: local
gather_facts: no
tasks:
- name: "Serching old git URL"
become: true
become_user: root
find:
paths: builds
file_type: file
recurse: yes
patterns:
- config$
use_regex: true
contains: 'atlgit-01.us.manh.com'
register: configfiles
- debug:
msg: "{{configfiles.files | map(attribute='path')| list }}"
Below is the 0utput
"/builds/v2020/app/db-upgradesetup-to/.git/config",
"/builds/v2020/app/db-upgradesetup-to/environments/configure/configureEnv.xml",
"/builds/v2020/app/db-upgradesetup-from/.git/config",
"/builds/v2020/app/db-upgradesetup-from/environments/configure/configureEnv.xml",
"/builds/v2020/app/db-upgradesetup-from/ui/help/Content/Resources/images/config.gif",
"/builds/v2020/app/db-upgradesetup-from/ui/help/Content/Resources/images/configure_button.gif",
"/builds/v2020/CI/source/dockerqa/.git/config",
"/builds/v2020/CI/source/docker_ci/.git/config",
"/builds/v2020/escrow/.git/config"
Thanks you for the help
There is an excludes option to the find command that I think will do what you want.
excludes: ‘.*./.git.config’
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/find_module.html