ansible: using with_items with notify handler

后端 未结 4 1808
再見小時候
再見小時候 2020-12-09 18:35

I want to pass a variable to a notification handler, but can\'t find anywhere be it here on SO, the docs or the issues in the github repo, how to do it. What I\'m doing is d

4条回答
  •  星月不相逢
    2020-12-09 19:02

    I finally solved it by splitting the apps out over multiple instances of the same role. This way, the handler in the role can refer to variables that are defined as role variable.

    In site.yml:

    - hosts: localhost
      roles:
      - role: something
        name: a
      - role: something
        name: b
    

    In roles/something/tasks/main.yml:

    - name: do something
      shell: "echo {{ name }}"
      notify: something happened
    
    - name: do something else
      shell: "echo {{ name }}"
      notify: something happened
    

    In roles/something/handlers/main.yml:

    - name: something happened
      debug:
        msg: "{{ name }}"
    

    Seems a lot less hackish than the first solution!

提交回复
热议问题