Additional conditions for tasks inside a block

柔情痞子 提交于 2019-12-02 09:53:12

You should fix the indentation of the when declarations.

Maybe it's not just possible in Ansible 2.4 to have enclosed tasks with additional conditions?

Ansible 2.4 works ok:

tasks:
  - block:

    - debug:
        msg: "task 1"

    - debug:
        msg: "task 2"
      when: false

    - debug:
        msg: "task 3"
      when: true

    when: true

results in:

TASK [debug] **************************************************************************************************
ok: [localhost] => {
    "msg": "task 1"
}

TASK [debug] **************************************************************************************************
skipping: [localhost]

TASK [debug] **************************************************************************************************
ok: [localhost] => {
    "msg": "task 3"
}

And you can always reorder the keys in block task for clarity:

tasks:
  - when: true
    block:
      - debug:
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!