Additional conditions for tasks inside a block

前端 未结 1 597
醉梦人生
醉梦人生 2021-01-27 23:18

I\'m trying to enclose tasks in the block with some when condition. Also some tasks inside this block have additional conditions. The problem is such tasks (with additional cond

相关标签:
1条回答
  • 2021-01-27 23:55

    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:
    
    0 讨论(0)
提交回复
热议问题