Including/Importing an Ansible role w/ handlers more than once
Including/Importing an Ansible role w/ handlers more than once
cross-posted from: https://lemmy.ml/post/4593804
Originally discussed on Matrix. ——— TLDR; Ansible handlers are added to the global namespace. ——— Suppose you've got a role which defines a handler
MyHandler:- name: MyHandler ... listen: "some-topic"Each time you
import/includeyour role, a new reference toMyHandleris added to the global namespace. As a result, when younotifyyour handler via the topics itlistens to (ienotify: "some-topic"), all the references toMyHandlerwill be executed by Ansible. If that's not what you want, you shouldnotifythe handler by name (ienotify: MyHandler) in which case Ansible will stop searching for other references as soon as it finds the first occurrence ofMyHandler. That meansMyHandlerwill be executed only once.
Comments