Ansible - HTTP Error 502: Bad Gateway when using script with XMLRPC - ansible

I have this script, that connects to service via XMLRPC, like:
import odoorpc
odoo = odoorpc.ODOO(host, protocol=protocol, port=port)
Task from yaml file:
- name: Change Odoo admin user password
ansible.builtin.script: "change-user-password \
{{ secrets_odoo_init_user_passwords_file }} --ignore-failed-login \
--host {{ ansible_host }} --port 443 --protocol jsonrpc+ssl"
become: true
become_user: "{{ app_user }}"
Call looks like this (from ansible logs):
<my-host> SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=30m -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/tmp/ansible-ssh-%h-%p-%r -tt my-host '/bin/sh -c '"'"'sudo -H -S -n -u odoo /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-lsrscdzqfzfliptrdleqjxcwaseuaggn ; /var/tmp/ansible-tmp-1635367335.375884-2165879-123865031409885/change-user-password /opt/odoo/.secrets/odoo_init_user_passwords_file --ignore-failed-login --host my-host --port 443 --protocol jsonrpc+ssl'"'"'"'"'"'"'"'"' && sleep 0'"'"''
The full traceback is:
NoneType: None
fatal: [dev]: FAILED! => {
"changed": true,
"msg": "non-zero return code",
"rc": 1,
"stderr": "Shared connection to my-host closed.\r\n",
"stderr_lines": [
"Shared connection to my-host closed."
],
"stdout": "Traceback (most recent call last):\r\n File \"/var/tmp/ansible-tmp-1635367335.375884-2165879-123865031409885/change-user-password\", line 109, in <module>\r\n odoo = login(\r\n File \"/var/tmp/ansible-tmp-1635367335.375884-2165879-123865031409885/change-user-password\", line 75, in login\r\n odoo = odoorpc.ODOO(host, protocol=protocol, port=port)\r\n File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/odoo.py\", line 95, in __init__\r\n self._connector = rpc.PROTOCOLS[protocol](\r\n File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/__init__.py\", line 288, in __init__\r\n super(ConnectorJSONRPCSSL, self).__init__(\r\n File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/__init__.py\", line 211, in __init__\r\n self._proxy_json, self._proxy_http = self._get_proxies()\r\n File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/__init__.py\", line 235, in _get_proxies\r\n result = proxy_json('/web/webclient/version_info')['result']\r\n File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/jsonrpclib.py\", line 113, in __call__\r\n response = self._opener.open(request, timeout=self._timeout)\r\n File \"/usr/lib/python3.9/urllib/request.py\", line 523, in open\r\n response = meth(req, response)\r\n File \"/usr/lib/python3.9/urllib/request.py\", line 632, in http_response\r\n response = self.parent.error(\r\n File \"/usr/lib/python3.9/urllib/request.py\", line 561, in error\r\n return self._call_chain(*args)\r\n File \"/usr/lib/python3.9/urllib/request.py\", line 494, in _call_chain\r\n result = func(*args)\r\n File \"/usr/lib/python3.9/urllib/request.py\", line 641, in http_error_default\r\n raise HTTPError(req.full_url, code, msg, hdrs, fp)\r\nurllib.error.HTTPError: HTTP Error 502: Bad Gateway\r\n",
"stdout_lines": [
"Traceback (most recent call last):",
" File \"/var/tmp/ansible-tmp-1635367335.375884-2165879-123865031409885/change-user-password\", line 109, in <module>",
" odoo = login(",
" File \"/var/tmp/ansible-tmp-1635367335.375884-2165879-123865031409885/change-user-password\", line 75, in login",
" odoo = odoorpc.ODOO(host, protocol=protocol, port=port)",
" File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/odoo.py\", line 95, in __init__",
" self._connector = rpc.PROTOCOLS[protocol](",
" File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/__init__.py\", line 288, in __init__",
" super(ConnectorJSONRPCSSL, self).__init__(",
" File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/__init__.py\", line 211, in __init__",
" self._proxy_json, self._proxy_http = self._get_proxies()",
" File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/__init__.py\", line 235, in _get_proxies",
" result = proxy_json('/web/webclient/version_info')['result']",
" File \"/opt/odoo/.local/lib/python3.9/site-packages/odoorpc/rpc/jsonrpclib.py\", line 113, in __call__",
" response = self._opener.open(request, timeout=self._timeout)",
" File \"/usr/lib/python3.9/urllib/request.py\", line 523, in open",
" response = meth(req, response)",
" File \"/usr/lib/python3.9/urllib/request.py\", line 632, in http_response",
" response = self.parent.error(",
" File \"/usr/lib/python3.9/urllib/request.py\", line 561, in error",
" return self._call_chain(*args)",
" File \"/usr/lib/python3.9/urllib/request.py\", line 494, in _call_chain",
" result = func(*args)",
" File \"/usr/lib/python3.9/urllib/request.py\", line 641, in http_error_default",
" raise HTTPError(req.full_url, code, msg, hdrs, fp)",
"urllib.error.HTTPError: HTTP Error 502: Bad Gateway"
]
}
I read that people workaround this error by using headers={'User-Agent': 'Mozilla/5.0'}. But if I use script module via ansible, how can I specify such header?
The thing is, I only get this error if I run script via ansible. I tried running that script explicitly from my machine and from target machine. In those cases, it works fine.
ansible [core 2.11.6]
config file = /home/oerp/.ansible.cfg
configured module search path = ['/home/oerp/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/oerp/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/oerp/.ansible/collections:/usr/share/ansible/collections
executable location = /home/oerp/.local/bin/ansible
python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
jinja version = 3.0.1
libyaml = True
Update
Turn out the problem when XMLPRC call is made, service is not yet running, thus the error.
So I have to use RPC only when service is already running.
I tried using wait_for like this (note, my Odoo service port is not exposed via compose, its only accessible through docker network by nginx):
- name: Save Odoo container status
set_fact:
odoo_ip: "{{ docker_compose_output.services.odoo.app_odoo_1.networks.app_backend.IPAddress }}"
- name: Wait for IP to be active
wait_for:
host: "{{ odoo_ip }}"
delay: 1
state: drained
I do get this error:
The full traceback is:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1635403378.5625799-2174550-176521610555803/AnsiballZ_wait_for.py", line 100, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1635403378.5625799-2174550-176521610555803/AnsiballZ_wait_for.py", line 92, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1635403378.5625799-2174550-176521610555803/AnsiballZ_wait_for.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.wait_for', init_globals=dict(_module_fqn='ansible.modules.wait_for', _modlib_path=modlib_path),
File "/usr/lib/python3.9/runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_wait_for_payload_pic_t21b/ansible_wait_for_payload.zip/ansible/modules/wait_for.py", line 674, in <module>
File "/tmp/ansible_wait_for_payload_pic_t21b/ansible_wait_for_payload.zip/ansible/modules/wait_for.py", line 657, in main
File "/tmp/ansible_wait_for_payload_pic_t21b/ansible_wait_for_payload.zip/ansible/modules/wait_for.py", line 356, in __init__
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
fatal: [dev]: FAILED! => {
"changed": false,
"module_stderr": "Shared connection to my-host closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/root/.ansible/tmp/ansible-tmp-1635403378.5625799-2174550-176521610555803/AnsiballZ_wait_for.py\", line 100, in <module>\r\n _ansiballz_main()\r\n File \"/root/.ansible/tmp/ansible-tmp-1635403378.5625799-2174550-176521610555803/AnsiballZ_wait_for.py\", line 92, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/root/.ansible/tmp/ansible-tmp-1635403378.5625799-2174550-176521610555803/AnsiballZ_wait_for.py\", line 40, in invoke_module\r\n runpy.run_module(mod_name='ansible.modules.wait_for', init_globals=dict(_module_fqn='ansible.modules.wait_for', _modlib_path=modlib_path),\r\n File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\r\n return _run_module_code(code, init_globals, run_name, mod_spec)\r\n File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n _run_code(code, mod_globals, init_globals,\r\n File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\r\n exec(code, run_globals)\r\n File \"/tmp/ansible_wait_for_payload_pic_t21b/ansible_wait_for_payload.zip/ansible/modules/wait_for.py\", line 674, in <module>\r\n File \"/tmp/ansible_wait_for_payload_pic_t21b/ansible_wait_for_payload.zip/ansible/modules/wait_for.py\", line 657, in main\r\n File \"/tmp/ansible_wait_for_payload_pic_t21b/ansible_wait_for_payload.zip/ansible/modules/wait_for.py\", line 356, in __init__\r\nTypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
Its unclear what argument it is about.

Turns out, the problem was that service (container) I was trying to connect with RPC was not yet running and that was causing bad gateway problem.
In my playbook, container is stopped and then started and just after initiating start, it tries to use RPC, which would fail (as my reverse proxy, which is nginx, would not yet see odoo service).
So simple fix is this:
- name: Pause for 3 seconds for Odoo service to load
pause:
seconds: 3
Though its not ideal as I can't be sure that I would need 3 seconds. It might be too long or too fast.
I tried using wait_for, but got some confusing errors. I think wait_for is better approach as it could react better than simple pause.
Update
Better way would be to use wait_for, so we don't need to specify specific delay time. Like (this way it waits till service is ready to be used):
- name: Save Odoo container status
set_fact:
odoo_ip: "{{ docker_compose_output.services.odoo.app_odoo_1.networks\
.app_backend.IPAddress }}"
- name: Wait for IP to be active
wait_for:
host: "{{ odoo_ip }}"
port: 8069
state: started

Related

"MODULE FAILURE\nSee stdout/stderr for the exact error"

im try to install grafana on ansible playbook, and I try this in a CentOS 7 OS, my task is using "ansible.builtin.yum" that I found in ansible documentation like this:
- name: Install the grafana rpm from a remote repo
ansible.builtin.yum:
name: https://dl.grafana.com/oss/release/grafana-{{ grafana_version }}.x86_64.rpm
state: present
With the grafana_version set in the default file...
But the task give me a problem with the msg "MODULE FAILURE\nSee stdout/stderr for the exact error"
I reed that is a problem with the sudoers but i dont have the access to this by my ssh.
The problem:
FAILED! => {"changed": false, "module_stderr": "Shared connection to (SSH) closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n File \"/home/user/.ansible/tmp/ansible-tmp-1672318071.738662-2292270-253361333856714/AnsiballZ_dnf.py\", line 107, in <module>\r\n _ansiballz_main()\r\n File \"/home/user/.ansible/tmp/ansible-tmp-1672318071.738662-2292270-253361333856714/AnsiballZ_dnf.py\", line 99, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/user/.ansible/tmp/ansible-tmp-1672318071.738662-2292270-253361333856714/AnsiballZ_dnf.py\", line 47, in invoke_module\r\n runpy.run_module(mod_name='ansible.modules.dnf', init_globals=dict(_module_fqn='ansible.modules.dnf', _modlib_path=modlib_path),\r\n File \"<frozen runpy>\", line 226, in run_module\r\n File \"<frozen runpy>\", line 98, in _run_module_code\r\n File \"<frozen runpy>\", line 88, in _run_code\r\n File \"/tmp/ansible_ansible.legacy.dnf_payload_q_8jy3dh/ansible_ansible.legacy.dnf_payload.zip/ansible/modules/dnf.py\", line 1465, in <module>\r\n File \"/tmp/ansible_ansible.legacy.dnf_payload_q_8jy3dh/ansible_ansible.legacy.dnf_payload.zip/ansible/modules/dnf.py\", line 1454, in main\r\n File \"/tmp/ansible_ansible.legacy.dnf_payload_q_8jy3dh/ansible_ansible.legacy.dnf_payload.zip/ansible/modules/dnf.py\", line 1428, in run\r\n File \"/tmp/ansible_ansible.legacy.dnf_payload_q_8jy3dh/ansible_ansible.legacy.dnf_payload.zip/ansible/modules/dnf.py\", line 1073, in ensure\r\n File \"/tmp/ansible_ansible.legacy.dnf_payload_q_8jy3dh/ansible_ansible.legacy.dnf_payload.zip/ansible/modules/dnf.py\", line 973, in _install_remote_rpms\r\n File \"/usr/lib/python3.11/site-packages/dnf/base.py\", line 1341, in add_remote_rpms\r\n raise IOError(_(\"Could not open: {}\").format(' '.join(pkgs_error)))\r\nOSError: Could not open: /home/user/.ansible/tmp/ansible-tmp-1672318071.738662-2292270-253361333856714/grafana-9.3.2.x86_6438hmxnkk.rpm\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
I try install the grafana by binaty with the unarchive, and this make the download but take me anocther error with nor find the requested service grafana-server: host

Ansible: TypeError: 'timeout' object does not support indexing

I am running Ansible for VMware, I have two vCenters and some tasks, but one task is failing in one vCenter only. I am using the same Ansible server, same permissions and same username, running Ansible version 2.9.27, python 2.7.5 and VMware SDK, both vCenter/ESXi has the same version, and access, so I don't know why just one task is failing in one vCenter this is the task:
https://docs.ansible.com/ansible/latest/collections/community/vmware/vsphere_file_module.html
- name: Create directories on local datastore
community.vmware.vsphere_file:
host: "{{ vcenter_server }}"
username: "{{ provider.user }}"
password: "{{ provider.password }}"
validate_certs: "{{ provider.validate_certs }}"
#esxi_hostname: "{{ inventory_hostname }}"
datacenter: "{{ vcenter_datacenter }}"
datastore: "{{ local_log_datastore_prefix }}"
path: "{{ item }}"
state: directory
loop: "{{ esxi_local_datastore_folders }}"
This is the error :
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~root && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855 `" && echo ansible-tmp-1657748234.07-77454-176593688580855="` echo /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vsphere_file.py
<localhost> PUT /root/.ansible/tmp/ansible-local-774132iPz96/tmpUa3kiC TO /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855/AnsiballZ_vsphere_file.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855/ /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855/AnsiballZ_vsphere_file.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855/AnsiballZ_vsphere_file.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1657748234.07-77454-176593688580855/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_community.vmware.vsphere_file_payload_38e7eivm/ansible_community.vmware.vsphere_file_payload.zip/ansible_collections/community/vmware/plugins/modules/vsphere_file.py", line 194, in main
File "/tmp/ansible_community.vmware.vsphere_file_payload_38e7eivm/ansible_community.vmware.vsphere_file_payload.zip/ansible/module_utils/urls.py", line 1390, in open_url
File "/tmp/ansible_community.vmware.vsphere_file_payload_38e7eivm/ansible_community.vmware.vsphere_file_payload.zip/ansible/module_utils/urls.py", line 1294, in open
File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib64/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/usr/lib64/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/tmp/ansible_community.vmware.vsphere_file_payload_38e7eivm/ansible_community.vmware.vsphere_file_payload.zip/ansible/module_utils/urls.py", line 467, in https_open
File "/usr/lib64/python3.6/urllib/request.py", line 1352, in do_open
r = h.getresponse()
File "/usr/lib64/python3.6/http/client.py", line 1346, in getresponse
response.begin()
File "/usr/lib64/python3.6/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.6/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib64/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/lib64/python3.6/ssl.py", line 971, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib64/python3.6/ssl.py", line 833, in read
return self._sslobj.read(len, buffer)
File "/usr/lib64/python3.6/ssl.py", line 590, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1657748244.8-77454-4966237197380/AnsiballZ_vsphere_file.py", line 102, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1657748244.8-77454-4966237197380/AnsiballZ_vsphere_file.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1657748244.8-77454-4966237197380/AnsiballZ_vsphere_file.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vsphere_file', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible_collections/community/vmware/plugins/modules/vsphere_file.py", line 349, in <module>
File "/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible_collections/community/vmware/plugins/modules/vsphere_file.py", line 198, in main
TypeError: 'timeout' object does not support indexing
failed: [server01.loc -> localhost] (item=.locker-server01.loc) => {
"ansible_loop_var": "item",
"changed": false,
"item": ".locker-server01.loc",
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible_collections/community/vmware/plugins/modules/vsphere_file.py\", line 194, in main\n File \"/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible/module_utils/urls.py\", line 1390, in open_url\n File \"/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible/module_utils/urls.py\", line 1294, in open\n File \"/usr/lib64/python3.6/urllib/request.py\", line 223, in urlopen\n return opener.open(url, data, timeout)\n File \"/usr/lib64/python3.6/urllib/request.py\", line 526, in open\n response = self._open(req, data)\n File \"/usr/lib64/python3.6/urllib/request.py\", line 544, in _open\n '_open', req)\n File \"/usr/lib64/python3.6/urllib/request.py\", line 504, in _call_chain\n result = func(*args)\n File \"/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible/module_utils/urls.py\", line 467, in https_open\n File \"/usr/lib64/python3.6/urllib/request.py\", line 1352, in do_open\n r = h.getresponse()\n File \"/usr/lib64/python3.6/http/client.py\", line 1346, in getresponse\n response.begin()\n File \"/usr/lib64/python3.6/http/client.py\", line 307, in begin\n version, status, reason = self._read_status()\n File \"/usr/lib64/python3.6/http/client.py\", line 268, in _read_status\n line = str(self.fp.readline(_MAXLINE + 1), \"iso-8859-1\")\n File \"/usr/lib64/python3.6/socket.py\", line 586, in readinto\n return self._sock.recv_into(b)\n File \"/usr/lib64/python3.6/ssl.py\", line 971, in recv_into\n return self.read(nbytes, buffer)\n File \"/usr/lib64/python3.6/ssl.py\", line 833, in read\n return self._sslobj.read(len, buffer)\n File \"/usr/lib64/python3.6/ssl.py\", line 590, in read\n v = self._sslobj.read(len, buffer)\nsocket.timeout: The read operation timed out\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-tmp-1657748244.8-77454-4966237197380/AnsiballZ_vsphere_file.py\", line 102, in <module>\n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-tmp-1657748244.8-77454-4966237197380/AnsiballZ_vsphere_file.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-tmp-1657748244.8-77454-4966237197380/AnsiballZ_vsphere_file.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vsphere_file', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible_collections/community/vmware/plugins/modules/vsphere_file.py\", line 349, in <module>\n File \"/tmp/ansible_community.vmware.vsphere_file_payload_ds9zbmfy/ansible_community.vmware.vsphere_file_payload.zip/ansible_collections/community/vmware/plugins/modules/vsphere_file.py\", line 198, in main\nTypeError: 'timeout' object does not support indexing\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
I don't know why just one task is failing in one vCenter
You get the error mostly because of a connection problem.
File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
...
File "... ansible/module_utils/urls.py", line 467, in https_open
File "/usr/lib64/python3.6/urllib/request.py", line 1352, in do_open
r = h.getresponse()
...
File "/usr/lib64/python3.6/ssl.py", line 833, in read
return self._sslobj.read(len, buffer)
File "/usr/lib64/python3.6/ssl.py", line 590, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
The request is timing out or do not get data. You will need to find out why.
Than, because it is not possible to establish the communication fully and you get an error message, you get the next error.
TypeError: 'timeout' object does not support indexing
Which means just, it isn't possible to index the error message to anything meaningful for further processing within the module. That error, the last one comes from Python and has therefore not much to do with Ansible itself, apart from that Ansible and the modules are written in Python.
Further References
TypeError: object does not support indexing
TypeError : object does not support indexing
Python: Object does not support indexing
Object Does Not Support Indexing
Python: TypeError: object does not support indexing

Ansible cannot find the template dir

I am facing a very strange bug using Ansible.
I have a basic script using jinja templating.
My script is located inside a directory called junos.
I have specified that my templates will be located inside a directory called templates
Find here the script:
---
- name : Load and commit the config
hosts: access_sw
vars:
ansible_python_interpreter: /usr/bin/python3.6
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name : "Load config from local file and commit"
juniper_junos_config:
load: "merge"
template:
src: "./templates/intf.j2"
dest: "./build_conf/{{ inventory_hostname }}/intf.cfg"
vars:
host: "{{ inventory_hostname }}"
format: "set"
register: response
We can see the file exists:
(prompt)--> ls ./templates/intf.j2
./templates/intf.j2
And ansible react saying it cannot find the template file:
ansible-playbook --connection local -vvv -i junos_hosts.yml junos_sendconfig.yml
ansible-playbook 2.10.3
config file = None
configured module search path = ['/home/jpbz7878/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jpbz7878/.local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.8 (default, Apr 2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
No config file found; using defaults
host_list declined parsing /home/jpbz7878/Programming/Ansible/junos/junos_hosts.yml as it did not pass its verify_file() method
script declined parsing /home/jpbz7878/Programming/Ansible/junos/junos_hosts.yml as it did not pass its verify_file() method
Skipping empty key (Remote-PE) in group (remote_pe)
Parsed /home/jpbz7878/Programming/Ansible/junos/junos_hosts.yml inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: junos_sendconfig.yml **********************************************************************************************************************************************
1 plays in junos_sendconfig.yml
PLAY [Load and commit the config] *******************************************************************************************************************************************
META: ran handlers
TASK [Load config from local file and commit] *******************************************************************************************************************************
task path: /home/jpbz7878/Programming/Ansible/junos/junos_sendconfig.yml:12
<acc1> ESTABLISH LOCAL CONNECTION FOR USER: jpbz7878
<acc1> EXEC /bin/sh -c 'echo ~jpbz7878 && sleep 0'
<acc1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/jpbz7878/.ansible/tmp `"&& mkdir "` echo /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155 `" && echo ansible-tmp-1604716352.6777682-31418-79718055491155="` echo /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155 `" ) && sleep 0'
<acc2> ESTABLISH LOCAL CONNECTION FOR USER: jpbz7878
<acc2> EXEC /bin/sh -c 'echo ~jpbz7878 && sleep 0'
<acc2> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/jpbz7878/.ansible/tmp `"&& mkdir "` echo /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346 `" && echo ansible-tmp-1604716352.6911237-31419-243034751392346="` echo /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346 `" ) && sleep 0'
Using module file /home/jpbz7878/.ansible/roles/Juniper.junos/library/juniper_junos_config.py
<acc1> PUT /home/jpbz7878/.ansible/tmp/ansible-local-31411hu73ud51/tmpt2duaeb7 TO /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py
Using module file /home/jpbz7878/.ansible/roles/Juniper.junos/library/juniper_junos_config.py
<acc1> EXEC /bin/sh -c 'chmod u+x /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/ /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py && sleep 0'
<acc2> PUT /home/jpbz7878/.ansible/tmp/ansible-local-31411hu73ud51/tmpyv9dt8vx TO /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py
<acc2> EXEC /bin/sh -c 'chmod u+x /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/ /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py && sleep 0'
<acc1> EXEC /bin/sh -c '/usr/bin/python3.6 /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py && sleep 0'
<acc2> EXEC /bin/sh -c '/usr/bin/python3.6 /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py && sleep 0'
<acc2> EXEC /bin/sh -c 'rm -f -r /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py", line 102, in <module>
_ansiballz_main()
File "/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.juniper_junos_config', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_juniper_junos_config_payload_mt06_8b2/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py", line 1148, in <module>
File "/tmp/ansible_juniper_junos_config_payload_mt06_8b2/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py", line 1054, in main
File "/tmp/ansible_juniper_junos_config_payload_mt06_8b2/ansible_juniper_junos_config_payload.zip/ansible/module_utils/juniper_junos_common.py", line 1660, in load_configuration
File "/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/utils/config.py", line 557, in load
template = self.dev.Template(path)
File "/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py", line 516, in Template
return self._j2ldr.get_template(filename, parent, gvars)
File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "/usr/local/lib/python3.6/site-packages/jinja2/loaders.py", line 113, in load
source, filename, uptodate = self.get_source(environment, name)
File "/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py", line 73, in get_source
raise jinja2.TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: {'src': './templates/intf.j2', 'dest': './build_conf/acc2/intf.cfg'}
fatal: [acc2]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File \"/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py\", line 102, in <module>\n _ansiballz_main()\n File \"/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6911237-31419-243034751392346/AnsiballZ_juniper_junos_config.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.juniper_junos_config', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_juniper_junos_config_payload_mt06_8b2/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py\", line 1148, in <module>\n File \"/tmp/ansible_juniper_junos_config_payload_mt06_8b2/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py\", line 1054, in main\n File \"/tmp/ansible_juniper_junos_config_payload_mt06_8b2/ansible_juniper_junos_config_payload.zip/ansible/module_utils/juniper_junos_common.py\", line 1660, in load_configuration\n File \"/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/utils/config.py\", line 557, in load\n template = self.dev.Template(path)\n File \"/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py\", line 516, in Template\n return self._j2ldr.get_template(filename, parent, gvars)\n File \"/usr/local/lib/python3.6/site-packages/jinja2/environment.py\", line 830, in get_template\n return self._load_template(name, self.make_globals(globals))\n File \"/usr/local/lib/python3.6/site-packages/jinja2/environment.py\", line 804, in _load_template\n template = self.loader.load(self, name, globals)\n File \"/usr/local/lib/python3.6/site-packages/jinja2/loaders.py\", line 113, in load\n source, filename, uptodate = self.get_source(environment, name)\n File \"/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py\", line 73, in get_source\n raise jinja2.TemplateNotFound(template)\njinja2.exceptions.TemplateNotFound: {'src': './templates/intf.j2', 'dest': './build_conf/acc2/intf.cfg'}\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
<acc1> EXEC /bin/sh -c 'rm -f -r /home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py", line 102, in <module>
_ansiballz_main()
File "/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.juniper_junos_config', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_juniper_junos_config_payload_rjlq97ce/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py", line 1148, in <module>
File "/tmp/ansible_juniper_junos_config_payload_rjlq97ce/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py", line 1054, in main
File "/tmp/ansible_juniper_junos_config_payload_rjlq97ce/ansible_juniper_junos_config_payload.zip/ansible/module_utils/juniper_junos_common.py", line 1660, in load_configuration
File "/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/utils/config.py", line 557, in load
template = self.dev.Template(path)
File "/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py", line 516, in Template
return self._j2ldr.get_template(filename, parent, gvars)
File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "/usr/local/lib/python3.6/site-packages/jinja2/loaders.py", line 113, in load
source, filename, uptodate = self.get_source(environment, name)
File "/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py", line 73, in get_source
raise jinja2.TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: {'src': './templates/intf.j2', 'dest': './build_conf/acc1/intf.cfg'}
fatal: [acc1]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File \"/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py\", line 102, in <module>\n _ansiballz_main()\n File \"/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/jpbz7878/.ansible/tmp/ansible-tmp-1604716352.6777682-31418-79718055491155/AnsiballZ_juniper_junos_config.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.juniper_junos_config', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_juniper_junos_config_payload_rjlq97ce/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py\", line 1148, in <module>\n File \"/tmp/ansible_juniper_junos_config_payload_rjlq97ce/ansible_juniper_junos_config_payload.zip/ansible/modules/juniper_junos_config.py\", line 1054, in main\n File \"/tmp/ansible_juniper_junos_config_payload_rjlq97ce/ansible_juniper_junos_config_payload.zip/ansible/module_utils/juniper_junos_common.py\", line 1660, in load_configuration\n File \"/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/utils/config.py\", line 557, in load\n template = self.dev.Template(path)\n File \"/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py\", line 516, in Template\n return self._j2ldr.get_template(filename, parent, gvars)\n File \"/usr/local/lib/python3.6/site-packages/jinja2/environment.py\", line 830, in get_template\n return self._load_template(name, self.make_globals(globals))\n File \"/usr/local/lib/python3.6/site-packages/jinja2/environment.py\", line 804, in _load_template\n template = self.loader.load(self, name, globals)\n File \"/usr/local/lib/python3.6/site-packages/jinja2/loaders.py\", line 113, in load\n source, filename, uptodate = self.get_source(environment, name)\n File \"/home/jpbz7878/.local/lib/python3.6/site-packages/jnpr/junos/device.py\", line 73, in get_source\n raise jinja2.TemplateNotFound(template)\njinja2.exceptions.TemplateNotFound: {'src': './templates/intf.j2', 'dest': './build_conf/acc1/intf.cfg'}\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
PLAY RECAP ******************************************************************************************************************************************************************
acc1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
acc2 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Did anybody face this kind of issue?
If yes thanks for your help.
Regards.
You should use the variable playbook_dir :
template: "{{ playbook_dir }}/templates/intf.j2"
A complete list of special variables you will find here:
special variables link

Provisioning Grafana Datasource in Ansible using Lists

I'm having an issue provisioning Grafana datasources with host variables for api key and url.
My intent is to implement a common list of datasources across multiple Grafana hosts (test/dev platforms.) Each of these hosts has their own Grafana URL and API Key.
Running grafana_datasource explicitly works fine, and using variables in debug prints my expected values for API key and URL as expected, but using the same syntax in grafana_datasource causes issues.
I have created host variables in my inventory like so:
[hostgroup]
host1 grafapikey=loTsoFLeTTers grafurl=https://host1.net
host2 grafapikey=loTsoFLeTTers grafurl=https://host2.net
I then test referencing these variables in my playbook like this:
- name: what is grafurl
debug:
msg: "{{ hostvars[inventory_hostname].grafurl }}"
- name: what is grafapi
debug:
msg: "{{ hostvars[inventory_hostname].grafapikey }}"
# note output is identical whether using msg or var here
and the output is as expected:
TASK [what is grafurl] **************************
ok: [host1.net] => {
"msg": "https://host1.net/"
}
TASK [what is grafapi] **************************
ok: [host1.net] => {
"msg": "loTsoFLeTTers"
}
Also, defining all arguments explictly when running this command ad-hoc creates the datasource successfully.
user#ansible-host:~$ ansible host1.net -m grafana_datasource -a "grafana_api_key='LoTsofLettERs' grafana_url='https://host1.net' name=testds ds_type=mysql url='testurl' database='test'" -K
BECOME password:
host1.net | CHANGED => {
"changed": true,
"id": 2,
"msg": "Datasource testds created : Datasource added",
"name": "testds"
}
However, running the same adhoc command using variable references causes issues:
user#ansible-host:~$ ansible host1.net -m grafana_datasource -a "grafana_api_key='{{ hostvars[inventory_hostname].grafapikey }}' grafana_url='{{ hostvars[inventory_hostname].grafurl }}' name=testds ds_type=mysql url='testurl' database='test' validate_certs=no" -K
BECOME password:
scada.ifctrl.net | FAILED! => {
"changed": false,
"module_stderr": "Shared connection to scada.ifctrl.net closed.\r\n",
"module_stdout": ##see below
I get lengthy errors in playbook output describing unexpected empty JSON:
Traceback (most recent call last):
File \"/root/.ansible/tmp/ansible-tmp-1596750425.3152304-29947-100749071777145/AnsiballZ_grafana_datasource.py\", line 102, in <module>
_ansiballz_main()
File \"/root/.ansible/tmp/ansible-tmp-1596750425.3152304-29947-100749071777145/AnsiballZ_grafana_datasource.py\", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File \"/root/.ansible/tmp/ansible-tmp-1596750425.3152304-29947-100749071777145/AnsiballZ_grafana_datasource.py\", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.monitoring.grafana_datasource', init_globals=None, run_name='__main__', alter_sys=True)
File \"/usr/lib/python3.6/runpy.py\", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File \"/usr/lib/python3.6/runpy.py\", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File \"/usr/lib/python3.6/runpy.py\", line 85, in _run_code
exec(code, run_globals)
File \"/tmp/ansible_grafana_datasource_payload_pwpa837u/ansible_grafana_datasource_payload.zip/ansible/modules/monitoring/grafana_datasource.py\", line 683, in <module>
File \"/tmp/ansible_grafana_datasource_payload_pwpa837u/ansible_grafana_datasource_payload.zip/ansible/modules/monitoring/grafana_datasource.py\", line 665, in main
File \"/tmp/ansible_grafana_datasource_payload_pwpa837u/ansible_grafana_datasource_payload.zip/ansible/modules/monitoring/grafana_datasource.py\", line 504, in grafana_create_datasource
File \"/tmp/ansible_grafana_datasource_payload_pwpa837u/ansible_grafana_datasource_payload.zip/ansible/modules/monitoring/grafana_datasource.py\", line 397, in grafana_datasource_exists
File \"/usr/lib/python3.6/json/__init__.py\", line 354, in loads
return _default_decoder.decode(s)
File \"/usr/lib/python3.6/json/decoder.py\", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File \"/usr/lib/python3.6/json/decoder.py\", line 357, in raw_decode
raise JSONDecodeError(\"Expecting value\", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Is my syntax incorrect? Am I referencing variables incorrectly in the scope of grafana_datasource in my playbook?
The issue was that I had a trailing slash in my Grafana URL. Removing the slash resolved the problem.

An exception occurred during task execution

Following this http://docs.ansible.com/ansible/intro_installation.html I did
echo "127.0.0.1" > /etc/ansible/hosts
Then
ansible all -m ping --ask-pass
SSH password:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'EntryPoint' object has no attribute 'resolve'
127.0.0.1 | FAILED! => {
"failed": true,
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
So, using -vvv I get:
ansible -vvv all -m ping --ask-pass
No config file found; using defaults
SSH password:
Using module file /Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/modules/core/system/ping.py
<127.0.0.1> ESTABLISH CONNECTION FOR USER: None on PORT 22 TO 127.0.0.1
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/executor/task_executor.py", line 120, in run
res = self._execute()
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/executor/task_executor.py", line 457, in _execute
result = self._handler.run(task_vars=variables)
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/action/normal.py", line 33, in run
results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/action/__init__.py", line 583, in _execute_module
tmp = self._make_tmp_path(remote_user)
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/action/__init__.py", line 218, in _make_tmp_path
result = self._low_level_execute_command(cmd, sudoable=False)
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/action/__init__.py", line 726, in _low_level_execute_command
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/connection/paramiko_ssh.py", line 251, in exec_command
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/connection/__init__.py", line 51, in wrapped
self._connect()
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/connection/paramiko_ssh.py", line 139, in _connect
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
File "/Users/Snowcrash/Developer/Ansible/ansible/lib/ansible/plugins/connection/paramiko_ssh.py", line 208, in _connect_uncached
ssh.load_system_host_keys()
File "/Users/Snowcrash/Library/Python/2.7/lib/python/site-packages/paramiko/client.py", line 101, in load_system_host_keys
self._system_host_keys.load(filename)
File "/Users/Snowcrash/Library/Python/2.7/lib/python/site-packages/paramiko/hostkeys.py", line 101, in load
e = HostKeyEntry.from_line(line, lineno)
File "/Users/Snowcrash/Library/Python/2.7/lib/python/site-packages/paramiko/hostkeys.py", line 331, in from_line
key = RSAKey(data=decodebytes(key))
File "/Users/Snowcrash/Library/Python/2.7/lib/python/site-packages/paramiko/rsakey.py", line 58, in __init__
).public_key(default_backend())
File "/Users/Snowcrash/Library/Python/2.7/lib/python/site-packages/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
_default_backend = MultiBackend(_available_backends())
File "/Users/Snowcrash/Library/Python/2.7/lib/python/site-packages/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
"cryptography.backends"
AttributeError: 'EntryPoint' object has no attribute 'resolve'
127.0.0.1 | FAILED! => {
"failed": true,
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
Any suggestions?
AttributeError: 'EntryPoint' object has no attribute 'resolve' is an error caused when the version of setuptools that was loaded is too old. Try upgrading the setuptools in your environment.
cryptography documents a minimum setuptools version of >=11.3 (setup.py), but on occasion pip can fail to enforce this requirement.

Resources