mitogen: apt: AttributeError: module '__main__' has no attribute '_module_fqn'

  • Which version of Ansible are you running?
ansible [core 2.11.2] 
  config file = ~/.ansible.cfg
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/venv/lib/python3.9/site-packages/ansible
  ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/venv/bin/ansible
  python version = 3.9.6 (default, Jul 16 2021, 00:00:00) [GCC 11.1.1 20210531 (Red Hat 11.1.1-3)]
  jinja version = 3.0.1
  libyaml = True
  • Is your version of Ansible patched in any way? no
  • Are you running with any custom modules, or module_utils loaded? no
  • Have you tried the latest master version from Git? yes
  • Mention your host and target OS and versions
    • host: Fedora 34
    • target: Debian 10 docker image
  • Mention your host and target Python versions
    • host: Python 3.9
    • target: Python 3.7

Example Playbook:

---
- name: Converge
  hosts: all

  tasks:
    - name: install vim
      ansible.builtin.apt:
        name: vim
        state: present

Error:

The full traceback is:
Traceback (most recent call last):
  File "master:/usr/local/share/mitogen/ansible_mitogen/runner.py", line 975, in _run
    self._run_code(code, mod)
  File "master:/usr/local/share/mitogen/ansible_mitogen/runner.py", line 939, in _run_code
    exec(code, vars(mod))
  File "master:/usr/local/venv/lib/python3.9/site-packages/ansible/modules/apt.py", line 1310, in <module>
  File "master:/usr/local/venv/lib/python3.9/site-packages/ansible/modules/apt.py", line 1114, in main
  File "master:/usr/local/venv/lib/python3.9/site-packages/ansible/module_utils/common/respawn.py", line 39, in respawn_module
    payload = _create_payload()
  File "master:/usr/local/venv/lib/python3.9/site-packages/ansible/module_utils/common/respawn.py", line 76, in _create_payload
    module_fqn = sys.modules['__main__']._module_fqn
AttributeError: module '__main__' has no attribute '_module_fqn'
fatal: [linux-debian-10]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"master:/usr/local/share/mitogen/ansible_mitogen/runner.py\", line 975, in _run\n    self._run_code(code, mod)\n  File \"master:/usr/local/share/mitogen/ansible_mitogen/runner.py\", line 939, in _run_code\n    exec(code, vars(mod))\n  File \"master:/usr/local/venv/lib/python3.9/site-packages/ansible/modules/apt.py\", line 1310, in <module>\n  File \"master:/usr/local/venv/lib/python3.9/site-packages/ansible/modules/apt.py\", line 1114, in main\n  File \"master:/usr/local/venv/lib/python3.9/site-packages/ansible/module_utils/common/respawn.py\", line 39, in respawn_module\n    payload = _create_payload()\n  File \"master:/usr/local/venv/lib/python3.9/site-packages/ansible/module_utils/common/respawn.py\", line 76, in _create_payload\n    module_fqn = sys.modules['__main__']._module_fqn\nAttributeError: module '__main__' has no attribute '_module_fqn'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Verbose output: verbose.log.txt

Workarounds like:

  1. Adding vars: { mitogen_task_isolation: fork } to the task
  2. Adding ansible.builtin.apt to ALWAYS_FORK_MODULES in ansible_mitogen/planner.py

doesn’t work.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 9
  • Comments: 26 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I confirm this bug still exists.

I think you are missing the point of this bug; sure, I’d be nice to have a workaround by setting the python interpreter to a different binary, but that still wouldn’t fix this bug.

The problem is that the ansible API has changed, and this breaks specific mitogen workflows. The solution should thus be to fix mitogen, not to avoid the specific circumstances in which this workflow is triggered.

can confirm the lastest master still has this problem

Having same issue with Ansible + Mitogen 😦

Same here with ansible 4.x and 5.x, mitogen 3.2. Works with ansible 3.x.

I noticed that it happens only on first apt module invocation on fresh clean destination system - python3-apt package installed automatically before actually installing other packages with apt module. It always works on second run and after because python3-apt already installed. So I think task failed because of apt-related files changed during first run (module reuse on something, idk).

Confirmed workaround - install python3-apt package on destination system manually or via shell module before first apt module invocation:

- name: debian.yml | https://github.com/mitogen-hq/mitogen/issues/849 workaround
  shell:
    cmd: apt update && apt install -y python3-apt