【发布时间】:2017-03-03 20:07:01
【问题描述】:
在 ansible 2.1 中有 loop_control 功能,允许使用任务 includes + with_ 循环并将循环项变量传递给其任务。在运行剧本之前,我使用检查列表任务。但是当使用with_循环+任务include时,我无法检查包含文件中的列表任务。目前我正在使用 ansible 2.1.2.0,这是我的代码:
main.yml
- hosts: localhost
connection: local
vars:
var1:
- 1
- 2
tasks:
- name: debuging 1
debug: msg=debug1
- include: task1.yml var1=test1
with_items: "{{ var1 }}"
loop_control:
loop_var: var2
- name: debuging 2
debug: msg=debug2
task1.yml
- name: "task1-1"
debug: msg=task1-1
- name: "task1-2"
debug: msg=task1-2
运行ansible
$ ansible-playbook main1.yml -vv --list-tasks
No config file found; using defaults
1 plays in playbooks/main1.yml
playbook: playbooks/main1.yml
play #1 (localhost): localhost TAGS: []
tasks:
debuging 1 TAGS: []
include TAGS: []
debuging 2 TAGS: []
此外,当我在任务上应用标签时,验证剧本会变得更加困难,因为它无法显示。我认为,如果 ansible 还可以列出任务include 文件中的所有任务,就好像任务包含没有with_ 循环一样。我希望输出看起来像
...
play #1 (localhost): localhost TAGS: []
tasks:
debuging 1 TAGS: []
tasks1-1 TAGS: []
tasks1-2 TAGS: []
debuging 2 TAGS: []
...
不知道是不是bug
【问题讨论】: