How do I exit Ansible play without error on a condition

前端 未结 6 1638
我在风中等你
我在风中等你 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:26

    The following was helpful in my case, as meta: end_play seems to stop the execution for all hosts, not just the one that matches.

    First establish a fact:

    - name: Determine current version
      become: yes
      slurp:
        src: /opt/app/CHECKSUM
      register: version_check
      ignore_errors: yes
    
    - set_fact:
      is_update_needed: "{{ ( version_check['checksum'] | b64decode != installer_file.stat.checksum)  }}"
    

    Now include that part that should only executed on this condition:

    # update-app.yml can be placed in the same role folder
    - import_tasks: update-app.yml
      when: is_update_needed
    

提交回复
热议问题