Ansible 2.10.4 authorized_key - Syntax error

Hi all,

I’m trying to set up ansible.posix.authorized_key on my playbook, which look like this:

  • name: Set authorized key for Carol
    ansible.posix.authorized_key:
    user: carol
    state: present
    key: “{{ lookup(‘file’, ‘ssh-keys/carol’) }}”

When executing the playbook (ansible-playbook -i inventory main.yml), I get the following message:
TASK [Set authorized key for Carol] ********************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: SyntaxError: invalid syntax
fatal: [nzprodapp]: FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/bin/python”}, “changed”: false, “module_stderr”: “Shared connection to 192.168.199.3 closed.\r\n”, “module_stdout”: “Traceback (most recent call last):\r\n File "/home/lucas/.ansible/tmp/ansible-tmp-1608521692.1705554-90163-205930135785049/AnsiballZ_authorized_key.py", line 102, in \r\n _ansiballz_main()\r\n File "/home/lucas/.ansible/tmp/ansible-tmp-1608521692.1705554-90163-205930135785049/AnsiballZ_authorized_key.py", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File "/home/lucas/.ansible/tmp/ansible-tmp-1608521692.1705554-90163-205930135785049/AnsiballZ_authorized_key.py", line 40, in invoke_module\r\n runpy.run_module(mod_name=‘ansible_collections.ansible.posix.plugins.modules.authorized_key’, init_globals=None, run_name=‘main’, alter_sys=True)\r\n File "/usr/lib64/python2.6/runpy.py", line 136, in run_module\r\n fname, loader, pkg_name)\r\n File "/usr/lib64/python2.6/runpy.py", line 54, in _run_module_code\r\n mod_loader, pkg_name)\r\n File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code\r\n exec code in run_globals\r\n File "/tmp/ansible_ansible.posix.authorized_key_payload_fuOpH9/ansible_ansible.posix.authorized_key_payload.zip/ansible_collections/ansible/posix/plugins/modules/authorized_key.py", line 216, in \r\n File "/tmp/ansible_ansible.posix.authorized_key_payload_fuOpH9/ansible_ansible.posix.authorized_key_payload.zip/ansible/module_utils/urls.py", line 115, in \r\n File "/usr/lib/python2.6/site-packages/urllib3/init.py", line 7, in \r\n from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url\r\n File "/usr/lib/python2.6/site-packages/urllib3/connectionpool.py", line 105\r\n _blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK}\r\n ^\r\nSyntaxError: invalid syntax\r\n”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}

I don’t know what could be the problem here, as my syntax looks identical to the documentation. Could someone please advise?

Thanks and merry xmas! :slight_smile:
Lucas

Hi Lucas,

It seems that you are using Python 2.6 which is old and end-of-life. Please upgrade to the latest version of Python.

I got to know this by looking at log pasted in mail

/usr/lib/python2.6

Hi Abhijeet, thanks for your help.

Indeed the Python version is 2.6, but it works on another server with the same version. So that’s not the issue.

Any other ideas, please?

Thanks!

Lucas

You have a version of urllib3 installed which is not compatible with Python2.6.

You would either need to uninstall urllib3 on that target host, or downgrade it to a version that works with python2.6

The change to drop python2.6 support in urllib3 was done in https://github.com/urllib3/urllib3/commit/cb2159878f8b47c5b4bc6d159ae2857b85c0a197

That commit indicates that urllib3 1.24 was the first version to require python2.7 or newer. Which indicates that urllib3 1.23 is the newest version that you can have installed for py26.