ansible 1.6>在with_items循环中使用with_first_found?

bri*_*urg 7 ansible ansible-playbook

是否可以with_first_foundwith_items循环中使用,例如:

- 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
Run Code Online (Sandbox Code Playgroud)

似乎无法使其正常使用with_nested.

hka*_*iti 5

不支持组合循环,但您可以将它们用作查找:

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
Run Code Online (Sandbox Code Playgroud)