On Tue, 1 Sep 2020 09:21:06 -0700 (PDT)
LUCA CARANGELO <l.carang...@sirti.it> wrote:

> 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/ 

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"

-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200901191159.765951b6%40gmail.com.

Attachment: pgp0KpiZBy8fB.pgp
Description: OpenPGP digital signature

Reply via email to