Skip to content

ansible ansible-playbook crashing with exception #407

Description

@stratacast

When I run ansible-playbook with the latest builds, I get this traceback:

[ERROR]: Unexpected Exception, this is probably a bug: function() argument 'code' must be code, not str

Traceback (most recent call last):
  File "/opt/local/lib/python3.13/site-packages/ansible/cli/__init__.py", line 660, in cli_executor
    exit_code = cli.run()
  File "/opt/local/lib/python3.13/site-packages/ansible/cli/playbook.py", line 153, in run
    results = pbex.run()
  File "/opt/local/lib/python3.13/site-packages/ansible/executor/playbook_executor.py", line 117, in run
    self._tqm.load_callbacks()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/local/lib/python3.13/site-packages/ansible/executor/task_queue_manager.py", line 206, in load_callbacks
    stdout_callback = callback_loader.get(self._stdout_callback_name)
  File "/opt/local/lib/python3.13/site-packages/ansible/plugins/loader.py", line 979, in get
    ctx = self.get_with_context(name, *args, **kwargs)
  File "/opt/local/lib/python3.13/site-packages/ansible/plugins/loader.py", line 1024, in get_with_context
    self._module_cache[path] = self._load_module_source(python_module_name=plugin_load_context._python_module_name, path=path)
                               ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/lib/python3.13/site-packages/ansible/plugins/loader.py", line 943, in _load_module_source
    spec.loader.exec_module(module)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1027, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/root/.ansible/collections/ansible_collections/community/general/plugins/callback/yaml.py", line 54, in <module>
    class MyDumper(AnsibleDumper):
    ...<21 lines>...
            return node
TypeError: function() argument 'code' must be code, not str

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/local/lib/python3.13/site-packages/ansible/cli/__init__.py", line 669, in cli_executor
    raise AnsibleError("Unexpected Exception, this is probably a bug.") from ex
ansible.errors.AnsibleError: Unexpected Exception, this is probably a bug: function() argument 'code' must be code, not str

Activity

  1. jperkin commented on Nov 12, 2025

    @jperkin
    Collaborator

    I think this is being caused by whatever version of ansible collections you have installed in /root/.ansible/collections from the stack trace. That file is already shipped as part of ansible, i.e. /opt/local/lib/python3.13/site-packages/ansible_collections/community/general/plugins/callback/yaml.py. Could you try removing it?

  2. self-assigned this
    on Nov 12, 2025
  3. stratacast commented on Nov 13, 2025

    @stratacast
    Author

    Ah, that came to bite me. Well that solved one issue, onto a newer one. I've attempted targeting multiple target OSes (native zone, OpenBSD, Linux) and am getting this error

    ansible-playbook -vvv example.ssh.sshd_configs --check --limit example.com
    ansible-playbook [core 2.19.3]
      config file = /opt/local/etc/ansible/ansible.cfg
      configured module search path = ['/etc/ansible/modules']
      ansible python module location = /opt/local/lib/python3.13/site-packages/ansible
      ansible collection location = /root/.ansible/collections
      executable location = /opt/local/bin/ansible-playbook
      python version = 3.13.9 (main, Nov  6 2025, 19:59:12) [GCC 13.3.0] (/opt/local/bin/python3.13)
      jinja version = 3.1.6
      pyyaml version = 6.0.3 (without libyaml)
    Using /opt/local/etc/ansible/ansible.cfg as config file
    host_list declined parsing /opt/local/etc/ansible/hosts.yml as it did not pass its verify_file() method
    Parsed /opt/local/etc/ansible/hosts.yml inventory source with yaml plugin
    running playbook inside collection example.ssh
    redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
    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: sshd_configs.yaml ***********************************************************************************************************************************************************************************************************
    1 plays in /root/.ansible/collections/ansible_collections/example/ssh/playbooks/sshd_configs.yaml
    
    PLAY [example] ***********************************************************************************************************************************************************************************************************************
    
    TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************************
    task path: /root/.ansible/collections/ansible_collections/example/ssh/playbooks/sshd_configs.yaml:2
    <example.com> Attempting python interpreter discovery.
    <example.com> ESTABLISH SSH CONNECTION FOR USER: root
    <example.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=30m -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/724f31b55d"' -o NumberOfPasswordPrompts=1 example.com '/bin/sh -c '"'"'echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.13'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.12'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.11'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
    [ERROR]: A worker was found in a dead state
    

    I spent some time poking through some searches on this issue, and it is not yet clear to me why this one is appearing

  4. stratacast commented on Dec 4, 2025

    @stratacast
    Author

    Thought I'd mention the issue is still persisting after the latest updates to trunk. I may create a new zone for now on older quarterly branch since my SSL certs are about to expire :)

  5. added a commit that references this issue on May 6, 2026
  6. added a commit that references this issue on May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions