Copy condition based on presence in playbook templates folder

I need to copy a configuration file to hosts based on its custom presence in playbook templates folder.

As example :
CONSIDER TO APPLY TO AN INVENTORY

My hostname is HOST001 {{ inventory_hostname }}

if in my playbook tamplates folder there is a file named : configuration–HOST001
then copy module with :
src : “./templates/configuration–{{ inventory_hostname }}”
dst: "/tmp/

if ./templates/configuration–HOST001 does not exists
then copy module with :

src : “./templates/configuration”
dst: "/tmp/

Is there any way to do something like this ?
Please let me know

Use "first_found". For example
https://docs.ansible.com/ansible/latest/plugins/lookup/first_found.html#first-found-return-first-file-found-from-list

  - copy:
      src: "{{ lookup('first_found', params) }}"
      dest: /tmp
    vars:
      params:
        files:
          - "configuration--{{ inventory_hostname }}"
          - configuration
        paths:
          - "{{ playbook_dir }}/templates"

Hi Vladimir,

I’m going to test it immediately !

Thank you very much , I really appreciate it.

It works perfectly !

Thanks again