Skip to content

Commit

Permalink
Add fix to read correct socket path recieved from ansible-connection (a…
Browse files Browse the repository at this point in the history
…nsible#27560)

Currently socket path is send from `ansible-connection` (running as background
process) over stdout. This can conflict with debug logs that are also send on
stdout resulting in incorrect socket path received by the main process.

To avoid this add a socket path delimiter string which is recevied by
main process and socket path is retrieved based on delimiter string.

This implementation will change in future when ansible-connection
framework is made more robust.
  • Loading branch information
ganeshrn authored Aug 1, 2017
1 parent aa19563 commit bb998a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/ansible-connection
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Server():
break
time.sleep(1)
timeout -= 1
return (0, self.socket_path, '')
return 0, b'\n#SOCKET_PATH#: %s\n' % self.socket_path, ''


def communicate(sock, data):
Expand Down
20 changes: 16 additions & 4 deletions lib/ansible/plugins/connection/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ def _do_it(self, action):
(stdout, stderr) = p.communicate()
stdin.close()

return (p.returncode, stdout, stderr)
return (p, stdout, stderr)

def exec_command(self, cmd, in_data=None, sudoable=True):
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
return self._do_it('EXEC: ' + cmd)
p, out, err = self._do_it('EXEC: ' + cmd)
return p.returncode, out, err

def put_file(self, in_path, out_path):
super(Connection, self).put_file(in_path, out_path)
Expand All @@ -90,5 +91,16 @@ def run(self):
socket path exists. If the path exists (or the timeout has expired),
returns the socket path.
"""
rc, out, err = self._do_it('RUN:')
return to_text(out, errors='surrogate_or_strict')
p, out, err = self._do_it('RUN:')
while True:
out = out.strip()
if out == b'':
# EOF file found
return None
elif out.startswith(b'#SOCKET_PATH#'):
break
else:
out = p.stdout.readline()

socket_path = out.split(b'#SOCKET_PATH#: ', 1)[1]
return to_text(socket_path, errors='surrogate_or_strict')

0 comments on commit bb998a3

Please sign in to comment.