ansible: using with_items with notify handler

后端 未结 4 1807
再見小時候
再見小時候 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:12

    To update jarv's answer above, Ansible 2.5 replaces with_items with loop. When getting results, item by itself will not work. You will need to explicitly get the name, e.g., item.name.

    - hosts: localhost
      tasks:
      - file:  >
          path=/tmp/{{ item }}
          state=directory
        register: files_created
        loop:
          - one
          - two
        notify: some_handler
    
      handlers:
        - name: "some_handler"
          shell: "echo {{ item.name }} has changed!"
          when: item.changed
          loop: files_created.results
    

提交回复
热议问题