issue #369: disable reset_connection on Ansible<2.5.6

https://github.com/ansible/ansible/issues/27520
issue260
David Wilson 6 years ago
parent 8ed72e7e7b
commit 6c71c5bfef

@ -31,6 +31,7 @@ from __future__ import unicode_literals
import logging import logging
import os import os
import pprint
import random import random
import stat import stat
import time import time
@ -699,11 +700,16 @@ class Connection(ansible.plugins.connection.ConnectionBase):
representing the target. If no connection exists yet, ContextService representing the target. If no connection exists yet, ContextService
will establish it before returning it or throwing an error. will establish it before returning it or throwing an error.
""" """
dct = self.parent.call_service( try:
service_name='ansible_mitogen.services.ContextService', dct = self.parent.call_service(
method_name='get', service_name='ansible_mitogen.services.ContextService',
stack=mitogen.utils.cast(list(stack)), method_name='get',
) stack=mitogen.utils.cast(list(stack)),
)
except mitogen.core.CallError:
LOG.warning('Connection failed; stack configuration was:\n%s',
pprint.pformat(stack))
raise
if dct['msg']: if dct['msg']:
if dct['method_name'] in self.become_methods: if dct['method_name'] in self.become_methods:
@ -809,6 +815,10 @@ class Connection(ansible.plugins.connection.ConnectionBase):
self.broker = None self.broker = None
self.router = None self.router = None
reset_compat_msg = (
'Mitogen only supports "reset_connection" on Ansible 2.5.6 or later'
)
def reset(self): def reset(self):
""" """
Explicitly terminate the connection to the remote host. This discards Explicitly terminate the connection to the remote host. This discards
@ -816,6 +826,13 @@ class Connection(ansible.plugins.connection.ConnectionBase):
the 'disconnected' state, and informs ContextService the connection is the 'disconnected' state, and informs ContextService the connection is
bad somehow, and should be shut down and discarded. bad somehow, and should be shut down and discarded.
""" """
if self._play_context.remote_addr is None:
# <2.5.6 incorrectly populate PlayContext for reset_connection
# https://github.com/ansible/ansible/issues/27520
raise ansible.errors.AnsibleConnectionFailure(
self.reset_compat_msg
)
self._connect() self._connect()
self._mitogen_reset(mode='reset') self._mitogen_reset(mode='reset')

@ -9,6 +9,12 @@
- meta: end_play - meta: end_play
when: not is_mitogen when: not is_mitogen
- debug: msg="reset.yml skipped on Ansible<2.5.6"
when: ansible_version.full < '2.5.6'
- meta: end_play
when: ansible_version.full < '2.5.6'
- custom_python_detect_environment: - custom_python_detect_environment:
register: out register: out

Loading…
Cancel
Save