2016-11-19 40 views
1

我想疊加2 with_item。Ansible與with_item的疊加

在我試過,但它不工作的時刻:

- name: Create log folder 
    file: 
    dest={{ item.dest }} # item from first with_item 
    state=directory 
    mode=0755 
    with_items: 
    { dest: "{{ item.path_logs }}/gunicorn" } # item from flask apps 
    { dest: "{{ item.path_logs }}/nginx" } # item from flask apps 
    { dest: "{{ item.path_logs }}/supervisor" } # item from flask apps 
    with_items: "{{ flask_apps }}" 

是否有可能做到這一點,或者我應該做3個任務?

+0

仍然不清楚你在問什麼。 – helloV

回答

2

在文檔中有一個nested loops的示例。
對於你的情況:

- name: Create log folder 
    file: 
    dest: "{{ item.0.path }}/{{ item.1 }}" 
    state: directory 
    mode: 0755 
    with_nested: 
    - "{{ flask_apps }}" 
    - ['gunicorn','nginx','supervisor']