0
votes

I add users in a role which ran up to a few days without problems. Today it fails with DeprecationWarning: the imp module is deprecated. I assume that the problem was triggered by changing to use python3 (with ansible_python_interpreter: "/usr/bin/python3" which I had to do to avoid a warning about loading an apt module...).

The task is:

- name: Add the user xxx with uid xx and add to sudo
      user:
        name: xx
        comment: xx xx xx
        uid: xx
        shell: /bin/bash 
        groups:  sudo
        generate_ssh_key: yes 
        password: $6$U/xxx

Is there anything I can change in the task to avoid the problem?

Is there a way to avoid the warning? I have used arg: warning: false in other context but do not see how to use it here.

[19:44:50] createUsers : Add the user frankadmin with uid 1000 and add to sudo | seon | FAILED | 1.39s
{
  - rc: 1
  - msg: MODULE FAILURE
         See stdout/stderr for the exact error
  - module_stdout: /home/frankadmin/.ansible/tmp/ansible-tmp-1607971490.3432899-221136005152758/AnsiballZ_user.py:17: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Traceback (most recent call last):
  File "/tmp/ansible_user_payload_h5rh5z0f/ansible_user_payload.zip/ansible/module_utils/basic.py", line 279, in get_distribution
AttributeError: module 'platform' has no attribute '_supported_dists'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frankadmin/.ansible/tmp/ansible-tmp-1607971490.3432899-221136005152758/AnsiballZ_user.py", line 113, in <module>
    _ansiballz_main()
  File "/home/frankadmin/.ansible/tmp/ansible-tmp-1607971490.3432899-221136005152758/AnsiballZ_user.py", line 105, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/frankadmin/.ansible/tmp/ansible-tmp-1607971490.3432899-221136005152758/AnsiballZ_user.py", line 48, in invoke_module
    imp.load_module('__main__', mod, module, MOD_DESC)
  File "/usr/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.8/imp.py", line 169, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 604, in _exec
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/ansible_user_payload_h5rh5z0f/__main__.py", line 2611, in <module>
  File "/tmp/ansible_user_payload_h5rh5z0f/__main__.py", line 2516, in main
  File "/tmp/ansible_user_payload_h5rh5z0f/__main__.py", line 403, in __new__
  File "/tmp/ansible_user_payload_h5rh5z0f/ansible_user_payload.zip/ansible/module_utils/basic.py", line 337, in load_platform_subclass
  File "/tmp/ansible_user_payload_h5rh5z0f/ansible_user_payload.zip/ansible/module_utils/basic.py", line 289, in get_distribution
AttributeError: module 'platform' has no attribute 'dist'

  - module_stderr: Shared connection to 10.0.0.70 closed.

  - changed: False

My version info on the controller:

ansible --version ansible 2.7.7 config file = /etc/ansible/ansible.cfg configured module search path = ['/home/frank/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3/dist-packages/ansible executable location = /usr/bin/ansible python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]

1

1 Answers

1
votes

When editing the question, I realized that my ansible version is current for Debian buster, but not really up to date. I installed the version 2.9.3 from 2.9.6 (from buster backports) which resolved the underlying issue (depreciated `imp).

I leave the question in the hope it is helpful for others running in the same error message.