Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible 1.6 > using with_first_found in a with_items loop?

Is it possible to use with_first_found in a with_items loop such as:

- template:
    dest=/foo/{{ item.name }}-{{ item.branch | default('master') }}
    src={{ item }}
  with_first_found:
    - {{ item.name }}-{{ item.branch | default('master') }}
    - {{ item.name }}.j2
    - apache_site.j2
  with_items: apache_sites

Can't seem to make it work using with_nested.

like image 496
briceburg Avatar asked Mar 26 '14 22:03

briceburg


1 Answers

Combining loops is unsupported, but you can use them as lookups:

vars:
  site_locations:
    - {{ item.name }}-{{ item.branch | default('master') }}
    - {{ item.name }}.j2
    - apache_site.j2

tasks:
    - template:
         dest=/foo/{{ item.name }}-{{ item.branch | default('master') }}
         src={{ lookup('first_found', site_locations }}
      with_items: apache_sites
like image 145
hkariti Avatar answered Oct 23 '22 06:10

hkariti