How do I exit Ansible play without error on a condition

前端 未结 6 1646
我在风中等你
我在风中等你 2021-01-31 02:02

I want to exit without an error (I know about assert and fail modules) when I meet a certain condition. The following code exits but with a failure:

  tasks:

           


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 02:33

    A better and more logical way to solve it may be to do the reverse and rather than fail if there is nothing to upgrade (which is a separate step that does only that) you could append all your upgrading tasks with a conditional depending on the upgrade variable. In essence just add

    when: upgrading.changed
    

    to tasks that should be only executed during an upgrade.

    It is a bit more work, but it also brings clarity and self contains the logic that affects given task within itself, rather than depending on something way above which may or may not terminate it early.

提交回复
热议问题