Skip to content

Commit

Permalink
add note on write access to socket_path (ansible#67060)
Browse files Browse the repository at this point in the history
* Change socket_path error messages to not directly refer to socket_path
* Apply suggestions from code review

Co-Authored-By: Nathaniel Case <[email protected]>
  • Loading branch information
samccann and Qalthos authored Feb 11, 2020
1 parent 28543ae commit 7ef7c1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ Then review the log file and find the relevant error message in the rest of this
.. _socket_path_issue:

Category "socket_path issue"
============================
Troubleshooting socket path issues
==================================

**Platforms:** Any

The ``socket_path does not exist or cannot be found`` and ``unable to connect to socket`` messages are new in Ansible 2.5. These messages indicate that the socket used to communicate with the remote network device is unavailable or does not exist.

The ``Socket path does not exist or cannot be found`` and ``Unable to connect to socket`` messages are new in Ansible 2.5. These messages indicate that the socket used to communicate with the remote network device is unavailable or does not exist.

For example:

Expand All @@ -212,7 +211,7 @@ For example:
fatal: [spine02]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_TSqk5J/ansible_modlib.zip/ansible/module_utils/connection.py\", line 115, in _exec_jsonrpc\nansible.module_utils.connection.ConnectionError: socket_path does not exist or cannot be found\n",
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_TSqk5J/ansible_modlib.zip/ansible/module_utils/connection.py\", line 115, in _exec_jsonrpc\nansible.module_utils.connection.ConnectionError: Socket path XX does not exist or cannot be found. See Troubleshooting socket path issues in the Network Debug and Troubleshooting Guide\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
Expand All @@ -225,15 +224,17 @@ or
fatal: [spine02]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_TSqk5J/ansible_modlib.zip/ansible/module_utils/connection.py\", line 123, in _exec_jsonrpc\nansible.module_utils.connection.ConnectionError: unable to connect to socket\n",
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_TSqk5J/ansible_modlib.zip/ansible/module_utils/connection.py\", line 123, in _exec_jsonrpc\nansible.module_utils.connection.ConnectionError: Unable to connect to socket XX. See Troubleshooting socket path issues in Network Debug and Troubleshooting Guide\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
Suggestions to resolve:

Follow the steps detailed in :ref:`enable network logging <enable_network_logging>`.
#. Verify that you have write access to the socket path described in the error message.

#. Follow the steps detailed in :ref:`enable network logging <enable_network_logging>`.

If the identified error message from the log file is:

Expand Down
19 changes: 14 additions & 5 deletions lib/ansible/module_utils/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ def _exec_jsonrpc(self, name, *args, **kwargs):
reqid = req['id']

if not os.path.exists(self.socket_path):
raise ConnectionError('socket_path does not exist or cannot be found.'
'\nSee the socket_path issue category in Network Debug and Troubleshooting Guide')
raise ConnectionError(
'socket path %s does not exist or cannot be found. See Troubleshooting socket '
'path issues in the Network Debug and Troubleshooting Guide' % self.socket_path
)

try:
data = json.dumps(req, cls=AnsibleJSONEncoder)
Expand All @@ -149,8 +151,11 @@ def _exec_jsonrpc(self, name, *args, **kwargs):
try:
out = self.send(data)
except socket.error as e:
raise ConnectionError('unable to connect to socket. See the socket_path issue category in Network Debug and Troubleshooting Guide',
err=to_text(e, errors='surrogate_then_replace'), exception=traceback.format_exc())
raise ConnectionError(
'unable to connect to socket %s. See Troubleshooting socket path issues '
'in the Network Debug and Troubleshooting Guide' % self.socket_path,
err=to_text(e, errors='surrogate_then_replace'), exception=traceback.format_exc()
)

try:
response = json.loads(out)
Expand Down Expand Up @@ -198,7 +203,11 @@ def send(self, data):

except socket.error as e:
sf.close()
raise ConnectionError('unable to connect to socket', err=to_text(e, errors='surrogate_then_replace'), exception=traceback.format_exc())
raise ConnectionError(
'unable to connect to socket %s. See the socket path issue category in '
'Network Debug and Troubleshooting Guide' % self.socket_path,
err=to_text(e, errors='surrogate_then_replace'), exception=traceback.format_exc()
)

sf.close()

Expand Down

0 comments on commit 7ef7c1b

Please sign in to comment.