I want to check whether a file exists.
It works, when I have the exact file name 30-eakte-keepalive.conf
as below.
- name: check file existence
hosts: "{{ targets | default('postgres') }}"
vars:
object: /opt/db/data/postgres/data/conf.d/30-eakte-keepalive.conf # 00-ina-default.conf # 10-ssl.conf
tasks:
- name: check existence of "{{ object }}"
ansible.builtin.stat:
path: "{{ object }}" # /opt/db/postgres/nrpe
become: true
become_user: postgres
register: return_object
however I am not certain whether the name is identical exactly so I’d prefer to apply a wildcard in my search string like /opt/db/data/postgres/conf.d/*keepalive*.conf
how can I achieve this in a play as the above?
I tested /opt/db/data/postgres/conf.d/*keepalive*.conf
which returns a 'does not exist`, so the * does not seem to work as a wildcard here.
or is stat
not even the best module to do this?