2016-10-21 30 views
1

在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: [] 
... 

我不知道它是否是错误或不

回答

1

此行为是预期的行为。请阅读Dynamic versus Static Includes。从这一章

摘录:

当使用动态包括,它让这些限制的一点是重要的:
- 你不能使用通知来触发它来自一个动态的包括处理器的名字。
- 你不能使用--start-的任务在任务开始执行内部动态包括。
- 只存在于动态包含内的标签不会显示在-list-tags输出中。
- 只存在于动态包含内的任务不会显示在-list-tasks输出中。

+0

我得到了,感谢告知! –