Correct issue of handlers running on all hosts incorrectly

Also adds an integration test to catch this bug in the future.

Fixes #7559
pull/7567/head
James Cammarata 10 years ago
parent 617e7eaf5b
commit cfd8c685d1

@ -355,7 +355,7 @@ class PlayBook(object):
def _run_task_internal(self, task): def _run_task_internal(self, task):
''' run a particular module step in a playbook ''' ''' run a particular module step in a playbook '''
hosts = self._trim_unavailable_hosts(task.play._play_hosts) hosts = self._trim_unavailable_hosts(self.inventory.list_hosts(task.play._play_hosts))
self.inventory.restrict_to(hosts) self.inventory.restrict_to(hosts)
runner = ansible.runner.Runner( runner = ansible.runner.Runner(

@ -1,3 +1,2 @@
dependencies: dependencies: []
- prepare_tests

@ -16,8 +16,23 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: notify the handler
- name: reset handler_called variable to false for all hosts
set_fact:
handler_called: False
- name: notify the handler for host A only
shell: echo shell: echo
notify: notify:
- set handler fact - set handler fact
when: inventory_hostname == 'A'
- name: force handler execution now
meta: "flush_handlers"
- debug: var=handler_called
- name: validate the handler only ran on one host
assert:
that:
- "inventory_hostname == 'A' and handler_called == True or handler_called == False"

@ -17,8 +17,9 @@
- "not hostvars[inventory_hostname]['handler1_called']" - "not hostvars[inventory_hostname]['handler1_called']"
- "'handler2_called' in hostvars[inventory_hostname]" - "'handler2_called' in hostvars[inventory_hostname]"
#- hosts: testgroup - name: test handlers
# gather_facts: False hosts: testgroup
# connection: local gather_facts: False
# roles: connection: local
# - { role: test_handlers_meta } roles:
- { role: test_handlers }

Loading…
Cancel
Save