From 4f29b5a76ba183e10080cc8b653c617ef50d97d1 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Fri, 6 Sep 2019 14:23:18 +0530 Subject: [PATCH] Fix ansible-connection persist after playbook run complete issue (#61591) * Fix ansible-connection persist after playbook run issue * PR https://github.com/ansible/ansible/pull/59153 to add support for delaying the ansible-connection added an old issue of ansible-connection persisting even after playbook run is finished till either command timeout or connect timeout is triggered. ansible-connection persist after playbook execution is done and also delays the connection initilization untill a method in invoked from module side on the connection object. * Add chanegelog --- changelogs/fragments/ansible-connection_persist_issue.yaml | 2 ++ lib/ansible/cli/scripts/ansible_connection_cli_stub.py | 2 +- lib/ansible/plugins/connection/__init__.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-connection_persist_issue.yaml diff --git a/changelogs/fragments/ansible-connection_persist_issue.yaml b/changelogs/fragments/ansible-connection_persist_issue.yaml new file mode 100644 index 00000000000..d8783687e22 --- /dev/null +++ b/changelogs/fragments/ansible-connection_persist_issue.yaml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-connection persists even after playbook run is completed (https://github.com/ansible/ansible/pull/61591) diff --git a/lib/ansible/cli/scripts/ansible_connection_cli_stub.py b/lib/ansible/cli/scripts/ansible_connection_cli_stub.py index 07663683b10..5a61aa71674 100755 --- a/lib/ansible/cli/scripts/ansible_connection_cli_stub.py +++ b/lib/ansible/cli/scripts/ansible_connection_cli_stub.py @@ -120,7 +120,7 @@ class ConnectionProcess(object): def run(self): try: - while True: + while not self.connection._conn_closed: signal.signal(signal.SIGALRM, self.connect_timeout) signal.signal(signal.SIGTERM, self.handler) signal.alarm(self.connection.get_option('persistent_connect_timeout')) diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index 14973dd6f3a..818d3416922 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -275,6 +275,7 @@ class NetworkConnectionBase(ConnectionBase): def __init__(self, play_context, new_stdin, *args, **kwargs): super(NetworkConnectionBase, self).__init__(play_context, new_stdin, *args, **kwargs) self._messages = [] + self._conn_closed = False self._network_os = self._play_context.network_os @@ -335,6 +336,7 @@ class NetworkConnectionBase(ConnectionBase): self.queue_message('vvvv', 'reset call on connection instance') def close(self): + self._conn_closed = True if self._connected: self._connected = False