ansible-role-yedit icon indicating copy to clipboard operation
ansible-role-yedit copied to clipboard

Error: ImportError: No module named yaml

Open klemens-u opened this issue 4 years ago • 4 comments

Using Ubuntu 18.04 I get the following error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named yaml
fatal: [my-host]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "<stdin>", line 114, in <module>
      File "<stdin>", line 106, in _ansiballz_main
      File "<stdin>", line 49, in invoke_module
      File "/tmp/ansible_yedit_payload_fkAMVf/__main__.py", line 191, in <module>
    ImportError: No module named yaml
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

I already tried various variants of pip install pyaml, (python2, python3, earlier version) but to no success. Any ideas?

klemens-u avatar May 12 '20 06:05 klemens-u

Note: this happens only with python2

klemens-u avatar May 12 '20 09:05 klemens-u

I guess the package needed might be ruamel.yaml. But tried it no help too.

denisli2017 avatar Sep 06 '20 12:09 denisli2017

Hey, I had the same problem.

Installing the package python-yaml did it for me.

You can do this by running apt install python-yaml on the managed host or by creating an ansible task:

- name: ensure python-yaml is installed
  package:
    name: python-yaml
    state: present

jasperroloff avatar Sep 24 '20 20:09 jasperroloff

I had this issue in python3 using pyenv virtual environments on Macos. It seems like the correct python interpreter was not discovered. Fixed by setting the ANSIBLE_PYTHON_INTERPRETER environment variable as follows.

export ANSIBLE_PYTHON_INTERPRETER="$(which python)"

noziwatele avatar Jul 27 '22 01:07 noziwatele