【问题标题】:Ansible doesn't show tasks when including task file use "with_" loop包含任务文件使用“with_”循环时,Ansible 不显示任务
【发布时间】: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

【问题讨论】:

    标签: task ansible


    【解决方案1】:

    此行为是预期行为。请阅读Dynamic versus Static Includes

    摘自该章:

    使用动态包含时,请务必牢记以下限制:
    - 您不能使用 notify 来触发来自动态包含的处理程序名称。
    - 您不能使用 --start-at-task 在动态包含内的任务处开始执行。
    - 仅存在于动态包含中的标签不会显示在 –list-tags 输出中。
    - 仅存在于动态包含中的任务不会显示在 –list-tasks 输出中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      相关资源
      最近更新 更多