srikanthReddy
srikanthReddy

Reputation: 1

ansible playbook is failing with proxy error while triggering from cron tab. its working fine when triggered manually

The full traceback is:

File "/tmp/ansible_snow_record_payload_pzajzkn7/ansible_snow_record_payload.zip/ansible_collections/servicenow/servicenow/plugins/modules/snow_record.py", line 419, in main File "/usr/local/lib/python3.6/site-packages/pysnow/resource.py", line 118, in get return self._request.get(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/pysnow/request.py", line 114, in get return self._get_response("GET", stream=kwargs.pop("stream", False)) File "/usr/local/lib/python3.6/site-packages/pysnow/request.py", line 57, in _get_response method, self._url, stream=use_stream, params=params, timeout=self._timeout, **kwargs File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 510, in send raise ProxyError(e, request=request) fatal: [localhost]: FAILED! => { "changed": false, "invocation": { "module_args": { "attachment": null, "auth": "basic", "client_id": null, "client_secret": null, "data": { "state": 2 }, "display_value": false, "exclude_reference_link": false, "host": null, "instance": "servicenow instance name", "log_level": "normal", "lookup_field": "number", "number": "INC55558", "openid": null, "openid_issuer": null, "openid_scope": [ "openid" ], "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "raise_on_empty": true, "state": "present", "suppress_pagination_header": false, "table": "incident", "token": null, "username": "ansible" } }, "msg": "Failed to update record: HTTPSConnectionPool(host='.service-now.com', port=443): Max retries exceeded with url: /api/now/table/incident?sysparm_query=number%3DINC1118658&sysparm_limit=10000&sysparm_offset=0&sysparm_display_value=False&sysparm_suppress_pagination_header=False&sysparm_exclude_reference_link=False&sysparm_view=&sysparm_fields= (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:860: The handshake operation timed out',)))" }

PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

Upvotes: 0

Views: 517

Answers (1)

mdaniel
mdaniel

Reputation: 33203

It's because cron jobs run in a non-login shell, meaning they don't evaluate all the /etc/bash* (and certainly not $HOME/.bash* files) in the same way that a login shell does

If your job requires a proxy to work, you'll need to either wrap the ansible invocation in a wrapper shell script (one which sources those initialization files, or sets the proxy variables manually), or specify the proxy environment variables in the play's environment: keyword

Upvotes: 0

Related Questions