在2.1中有loop_control功能,允许使用任务includes
+ with_
循环并将循环项目变量传递给其任务。在运行playbook之前,我使用检查列表任务。但是当使用with_
循环+任务include
时,我无法检查包含文件中的列表任务。目前我使用ansible 2.1.2.0这里是我的代码:当包含任务文件使用“with_”循环时,Ansible不显示任务
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: []
...
我不知道它是否是错误或不
我得到了,感谢告知! –