How do I write an Ansible handler with multiple tasks?

前端 未结 3 404
青春惊慌失措
青春惊慌失措 2021-01-30 04:08

In response to a change, I have multiple related tasks that should run. How do I write an Ansible handler with multiple tasks?

For example, I would like a handler that r

3条回答
  •  伪装坚强ぢ
    2021-01-30 04:31

    In your handler file, chain the different steps together using notify.

    - name: Restart conditionally
      debug: msg=Step1
      changed_when: True
      notify: Restart conditionally step 2
    
    - name: Restart conditionally step 2
      debug: msg=Step2
      changed_when: True
      notify: Restart conditionally step 3
    
    - name: Restart conditionally step 3
      debug: msg=Step3
    

    Then refer to it from a task with notify: Restart conditionally.

    Note that you can only notify to handlers below the current one. So for example, Restart conditionally step 2 can't notify Restart conditionally.

    Source: #ansible at irc.freenode.net. I'm unsure whether this will continue to work in the future as it's not mentioned as a feature in the official documentation.

提交回复
热议问题