Apply with_items on multiple tasks

一世执手 提交于 2019-11-30 17:24:51

As of today you can use with_items with include, so you'd need to split your playbook into two files:

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

and subtasks.yml:

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

There is a request to make with_items applicable to block, but it is still not implemented.

You have the possibility to define a yaml list in a variables file:

---
myfiles:
- "file1.sh"
- "file2.sh"
...

and then you can use

with_items: "{{ myfiles }}"

in the task.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!