ansible – 在多个任务上应用with_items

是否可以将项目列表应用于Ansible playbook中的多个任务?举个例子:

- name: download and execute
  hosts: server1
  tasks:
  - get_url: url="some-url/{{item}}" dest="/tmp/{{item}}"
    with_items:
    - "file1.sh"
    - "file2.sh"
  - shell: /tmp/{{item}} >> somelog.txt
    with_items:
    - "file1.sh"
    - "file2.sh"

是否有一些语法来避免重复项目列表?

截至今天,您可以将with_items与include一起使用,因此您需要将Playbook拆分为两个文件:

- name: download and execute
  hosts: server1
  tasks:
  - include: subtasks.yml file={{item}}
    with_items:
    - "file1.sh"
    - "file2.sh"

和subtasks.yml:

- get_url: url="some-url/{{file}}" dest="/tmp/{{file}}"
- shell: /tmp/{{file}} >> somelog.txt

有一个request使with_items适用于阻止,但它仍然没有实现.

翻译自:https://stackoverflow.com/questions/39040521/apply-with-items-on-multiple-tasks

转载注明原文:ansible – 在多个任务上应用with_items