在多个任务上应用with_items [英] Apply with_items on multiple tasks

查看:87
本文介绍了在多个任务上应用with_items的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to apply a list of items to multiple tasks in an Ansible playbook? To give an example:

- 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"

是否有某种语法可以避免重复项目列表?

Is there some syntax to avoid the repetition of the item-list?

推荐答案

到目前为止,您可以将with_itemsinclude结合使用,因此需要将剧本拆分为两个文件:

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"

subtasks.yml:

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

有一个要求使得with_items适用于block,但是它仍然没有实现.

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

这篇关于在多个任务上应用with_items的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆