1

I m trying to install packages through Ansible but getting No module named yum error with python2.7. Anyone ever faced this issue before?

Braiam
  • 1
  • 11
  • 47
  • 78
cedrajin21
  • 65
  • 1
  • 8

3 Answers3

1

Fedora Core 3? No wonder! That release is from 2004. My memory of over a decade ago is a little hazy — it appears that yum was available in that release, but I think "up2date" was still the official higher-level package manager.

But, also, the yum version is 2.x, and it's packaged to work with the system Python of the time, which was Python 2.3. It's highly unlikely that the ansible module will work even with kludges. If you really need to install packages there, you will need to find an alternate way *. Plus, the mirror infrastructure for FC3 is no longer standing — you'll at the very least need to point to the archive.

I do, however, encourage you to use a newer version of Fedora if at all possible, not just for the convenience of things working (though, there's that) but because there are numerous known exploits which will work on FC3 — I would be very hesitant about having any Linux distro which reached end of life in 2006 on a network now. (Disclaimer: I happen to work on the current Fedora).


* alternate way: Easiest approach is probably skipping the yum module and just having ansible run the yum command directly.

mattdm
  • 2,082
  • 25
  • 39
  • I totally agree that this is a really old distribution. Also i m pointing base to the archive url for downloading packages! I really appreciate your time and suggestions. will see what i can do – cedrajin21 Apr 20 '15 at 16:49
1

My problem was I had set ansible_python_interpreter to something other than the default python since I needed a virtualenv python. The virtualenv python did not have the yum module installed.

Executing the yum statement before I set the ansible_python_interpreter fact fixed this for me. I could have also set the fact back to the original value ( usually /usr/bin/python ) if this wasn't an option.

For those looking to set this fact, you can use:

- set_fact:
    ansible_python_default_interpreter: "{{ ansible_python_interpreter }}"
    ansible_python_interpreter:  "{{ virtualenv_dir }}/bin/python"

Where {{ virtualenv_dir }} is the directory in which you used the pip module to install the virtual env as described at http://docs.ansible.com/ansible/pip_module.html .

And then to set it back:

- set_fact:
    ansible_python_interpreter:  "{{ ansible_python_default_interpreter }}"

This goes by whatever is returned by sys.executable , which is usually /usr/bin/python .

For the curious, this is the current code block at ansible/lib/ansible/inventory/__init__.py lines 461-462 (subject to change!):

if "ansible_python_interpreter" not in new_host.vars:
                new_host.set_variable("ansible_python_interpreter", sys.executable)

I found the pro tip about the interpreter fact in this thread. https://groups.google.com/forum/#!msg/ansible-project/yNWKzV5F-QU/e-vkWJKf6tQJ

saranicole
  • 2,093
  • 1
  • 23
  • 23
-2

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Reference: https://docs.python.org/2/tutorial/modules.html

If you are getting an error that states "No module named yum" this is a result of there not being a yum.py file.

Ansible and YUM are not supported on Windows systems. Reference: http://docs.ansible.com/intro_installation.html

Mike Stratton
  • 463
  • 1
  • 7
  • 20
  • This isn't necessarily true. In fact, it is _not_ the case with the yum python module. → http://stackoverflow.com/questions/448271/what-is-init-py-for – mattdm Apr 19 '15 at 15:36