with 專案 - 預定義的字典

可以使用字典建立更復雜的迴圈。

來自 vars:

packages:
  - present: tree
  - present: nmap
  - absent: apache2

然後迴圈:

- name: manage packages
  package: name={{ item.value }} state={{ item.key }}
  with_items: '{{ packages }}'

或者,如果你不喜歡使用鍵值:

瓦爾:

packages:
  - name: tree
    state: present
  - name: nmap
    state: present
  - name: apache2
    state: absent

然後迴圈:

- name: manage packages
  package: name={{ item.name }} state={{ item.state }}
  with_items: '{{ packages }}'