I am trying to develop an ansible module which would traverse subfolders under a main folder and list all .SQL files inside the sub-folders which were modified in the last 30 minutes. Below is my code:
- name: Install SQL scripts on Private PostgreSQL Instance
hosts: localhost
gather_facts: no
become: yes
tasks:
- name: install pip3
apt: name=python3-pip state=present
- name: Install required apt packages
apt:
name:
- libpq-dev
- name: Install required python packages
pip:
name:
- psycopg2
- name: Download cloudSQL proxy
ansible.builtin.get_url:
url: https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.13.0/cloud-sql-proxy.linux.amd64
dest: ./cloud-sql-proxy
mode: "0755"
- name: Set GCP project
command:
gcloud config set project '{{ gcp_project }}'
- name: Print gcloud config
command:
gcloud config list
- name: Start cloudSQL proxy
command: ./cloud-sql-proxy --private-ip "{{ gcp_project }}:{{ db_instance_location }}:{{ db_instance_name }}"
async: 3600
poll: 0
- name: List subfolders
find:
path: DDL/
recurse: no
file_type: directory
register: subfolders
- name: Find recently modified files in each subfolder
find:
path: "{{ item.path }}"
recurse: yes
patterns: "*.sql"
age: "-30m"
age_stamp: "mtime"
use_regex: yes
loop: "{{ subfolders.files }}"
register: recent_files_per_subfolder
loop_control:
label: "{{ item.path }}"
- name: Display files modified within the last 5 minutes for each subfolder
debug:
msg: "Files modified in {{ item.item.path }}: {{ item.files | map(attribute='path') | list }}"
loop: "{{ recent_files_per_subfolder.results }}"
when: subfolders.files | length > 0
However the playbook output not listing anything. I have tried changing the age parameter, but the output is same.
Any help would be really appreciated.