maxhoesel-ansible/ansible-collection-smallstep

Adding provisioner: "SyntaxError: invalid syntax"

strarsis opened this issue · 7 comments

When adding an acme provisioner, ansible fails with SyntaxError: invalid syntax error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: SyntaxError: invalid syntax
fatal: [localca]: FAILED! => {"changed": false, "module_stderr": "Shared connection to [...] closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/var/tmp/ansible-tmp-1630082859.6666074-4612-147676839279342/AnsiballZ_step_ca_provisioner.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/var/tmp/ansible-tmp-1630082859.6666074-4612-147676839279342/AnsiballZ_step_ca_provisioner.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/var/tmp/ansible-tmp-1630082859.6666074-4612-147676839279342/AnsiballZ_step_ca_provisioner.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.maxhoesel.smallstep.plugins.modules.step_ca_provisioner', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib64/python2.7/runpy.py\", line 170, in run_module\r\n    mod_name, loader, code, fname = _get_module_details(mod_name)\r\n  File \"/usr/lib64/python2.7/runpy.py\", line 113, in _get_module_details\r\n    code = loader.get_code(mod_name)\r\n  File \"/tmp/ansible_maxhoesel.smallstep.step_ca_provisioner_payload_ncWoUY/ansible_maxhoesel.smallstep.step_ca_provisioner_payload.zip/ansible_collections/maxhoesel/smallstep/plugins/modules/step_ca_provisioner.py\", line 263\r\n    module, result, {**args, **connection_run_args}\r\n                      ^\r\nSyntaxError: invalid syntax\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
    - name: Add an ACME provisioner to CA
      maxhoesel.smallstep.step_ca_provisioner:
        name: ACME
        type: ACME
      become_user: step-ca
      notify: reload step-ca

What version of Python are you using on the remote host? This colletion requires Python 3.6 or newer, so it might not work on older versions.

Specifically, the {**a, **b} syntax for merging dicts was introduced in Python 3.5.

Ah, I see. Python 2.7.5 is used on the remote host.

@maxhoesel:
I switched to Python 3 but now the installation is failing because of Python 2 and the package manager:

TASK [maxhoesel.smallstep.step_ca : Requirements are installed] ****************
fatal: [localca]: FAILED! => {"changed": false, "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}

@maxhoesel: OK, I got it solved with a relatively easy addition:

- name: Install python3 for some ansible modules
      package:
        name: python3
        state: present

- name: Add an ACME provisioner to CA
      maxhoesel.smallstep.step_ca_provisioner:
        name: ACME
        type: ACME
      become_user: step-ca
      notify: reload step-ca
      vars:
        ansible_python_interpreter: /usr/bin/python3

As an improvement: It may be a good idea if the module complain about the python version, so it is more clear why it failed.

A warning would be nice, but unfortunately wouldn't work in this case. If Python can't even run the module due to an "Invalid Syntax" error, then the module never gets to check the Python version. It might be a good idea to add a note to a potential collection FAQ in the future

@maxhoesel: It would be so great if this issue could be resolved: #114
It is blocking currently as I would have to manually fix the CA config JSON file and re-run everything.