From bfa41db5f0d08684ee9af9f2bf24bd1623582b4c Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Mon, 7 Jan 2019 12:32:55 -0500 Subject: [PATCH] [2.7] Don't fail if a remote_addr with a '/' hits ansible_connection (#49781) (#50037) * [2.7] Don't fail if a remote_addr with a '/' hits ansible_connection (#49781) * Fail if a remote_addr with a '/' hist ansible_connection This is _probably_ a CIDR block, but anything with a slash will fail, so no need to try to parse to make sure * Locks are now per-socket_path. Locks use the same value as socket_path. Locks are also cleaned up in shutdown like sockets. (cherry picked from commit 61a649c) Co-authored-by: Nathaniel Case * Add changelog --- bin/ansible-connection | 7 ++++++- changelogs/fragments/persistent-socket-lock-name.yaml | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/persistent-socket-lock-name.yaml diff --git a/bin/ansible-connection b/bin/ansible-connection index ac378a4d872..cc2a924baaa 100755 --- a/bin/ansible-connection +++ b/bin/ansible-connection @@ -182,6 +182,7 @@ class ConnectionProcess(object): def shutdown(self): """ Shuts down the local domain socket """ + lock_path = unfrackpath("%s/.ansible_pc_lock_%s" % os.path.split(self.socket_path)) if os.path.exists(self.socket_path): try: if self.sock: @@ -195,6 +196,10 @@ class ConnectionProcess(object): os.remove(self.socket_path) setattr(self.connection, '_socket_path', None) setattr(self.connection, '_connected', False) + + if os.path.exists(lock_path): + os.remove(lock_path) + display.display('shutdown complete', log_only=True) @@ -249,8 +254,8 @@ def main(): tmp_path = unfrackpath(C.PERSISTENT_CONTROL_PATH_DIR) makedirs_safe(tmp_path) - lock_path = unfrackpath("%s/.ansible_pc_lock_%s" % (tmp_path, play_context.remote_addr)) socket_path = unfrackpath(cp % dict(directory=tmp_path)) + lock_path = unfrackpath("%s/.ansible_pc_lock_%s" % os.path.split(socket_path)) with file_lock(lock_path): if not os.path.exists(socket_path): diff --git a/changelogs/fragments/persistent-socket-lock-name.yaml b/changelogs/fragments/persistent-socket-lock-name.yaml new file mode 100644 index 00000000000..f8c563ad854 --- /dev/null +++ b/changelogs/fragments/persistent-socket-lock-name.yaml @@ -0,0 +1,6 @@ +--- +bugfixes: +- Changes how ansible-connection names socket lock files. They now use + the same name as the socket itself, and as such do not lock other + attempts on connections to the same host, or cause issues with + overly-long hostnames.