Giter Club home page Giter Club logo

Comments (6)

Cantonious avatar Cantonious commented on August 15, 2024 6

Kind of a necro here, but wanted to update for anyone else running into issues with this:

django 2.X is not compatible with python2.7, which is the default in the centos7 image.

Installing django can be accomplished by first installing the pip module:
ansible app -b easy_install -a "name=pip state=present"
and then installing django through pip:
ansible app -b -m pip -a "name=django version=1.11.8 state=present"

https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django

The following error is received using ansible app -b -m easy_install -a "name=django state=present" without following the above procedure:

192.168.60.4 | FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "Traceback (most recent call last):\n  File \"/bin/easy_install\", line 9, in <module>\n    load_entry_point('setuptools==0.9.8', 'console_scripts', 'easy_install')()\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 1992, in main\n    with_ei_usage(lambda:\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 1979, in with_ei_usage\n    return f()\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 1996, in <lambda>\n    distclass=DistributionWithoutHelpCommands, **kw\n  File \"/usr/lib64/python2.7/distutils/core.py\", line 152, in setup\n    dist.run_commands()\n  File \"/usr/lib64/python2.7/distutils/dist.py\", line 953, in run_commands\n    self.run_command(cmd)\n  File \"/usr/lib64/python2.7/distutils/dist.py\", line 972, in run_command\n    cmd_obj.run()\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 380, in run\n    self.easy_install(spec, not self.no_deps)\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 623, in easy_install\n    return self.install_item(spec, dist.location, tmpdir, deps)\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 653, in install_item\n    dists = self.install_eggs(spec, download, tmpdir)\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 849, in install_eggs\n    return self.build_and_install(setup_script, setup_base)\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 1130, in build_and_install\n    self.run_setup(setup_script, setup_base, args)\n  File \"/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py\", line 1115, in run_setup\n    run_setup(setup_script, args)\n  File \"/usr/lib/python2.7/site-packages/setuptools/sandbox.py\", line 69, in run_setup\n    lambda: execfile(\n  File \"/usr/lib/python2.7/site-packages/setuptools/sandbox.py\", line 120, in run\n    return func()\n  File \"/usr/lib/python2.7/site-packages/setuptools/sandbox.py\", line 71, in <lambda>\n    {'__file__':setup_script, '__name__':'__main__'}\n  File \"setup.py\", line 32, in <module>\n  File \"/tmp/easy_install-2joQDq/Django-2.0/django/__init__.py\", line 1, in <module>\n  File \"/tmp/easy_install-2joQDq/Django-2.0/django/utils/version.py\", line 61, in <module>\nAttributeError: 'module' object has no attribute 'lru_cache'\n"
}

from ansible-for-devops.

rvbhute avatar rvbhute commented on August 15, 2024

Output of trying to use easy_install and pip (showing output for only one app server)

rohit@ryujin:ansible-chap3$ ansible app -s -m easy_install -a "name=django"
192.168.60.5 | SUCCESS => {
    "binary": "/bin/easy_install", 
    "changed": false, 
    "name": "django", 
    "virtualenv": null
}

rohit@ryujin:ansible-chap3$ ansible app -a "python -c 'import django; print django.get_version()'"
192.168.60.5 | FAILED | rc=1 >>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named django

rohit@ryujin:ansible-chap3$ ansible app -s -m pip -a "name=django"
192.168.60.5 | SUCCESS => {
    "changed": true, 
    "cmd": "/bin/pip install django", 
    "name": "django", 
    "requirements": null, 
    "state": "present", 
    "stderr": "You are using pip version 8.1.0, however version 8.1.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.\n", 
    "stdout": "Collecting django\n  Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)\nInstalling collected packages: django\nSuccessfully installed django-1.9.5\n", 
    "stdout_lines": [
        "Collecting django", 
        "  Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)", 
        "Installing collected packages: django", 
        "Successfully installed django-1.9.5"
    ], 
    "version": null, 
    "virtualenv": null
}

rohit@ryujin:ansible-chap3$ ansible app -a "python -c 'import django; print django.get_version()'"
192.168.60.5 | SUCCESS | rc=0 >>
1.9.5

from ansible-for-devops.

tschutte avatar tschutte commented on August 15, 2024

I just ran into the same issue trying to follow this example. I finally determined that while the base centos7 image claims that python-backports and python-backports-ssl_match_hostname packages are installed, the contents are not present in /usr/lib/python2.7/site-packages/.

Removing the python-backports package and then installing python-setuptools normally seems to fix the issue.
ansible app -s -a "yum remove python-backports"
ansible app -s -m yum -a "name=python-setuptools state=present"
...

I didn't dig into why the provided centos7 image is broken in the first place.

from ansible-for-devops.

geerlingguy avatar geerlingguy commented on August 15, 2024

Taking a look—thanks for the detailed reports! Probably just a result of one of the base changes that were made in CentOS 7 (vs 6, which this example originally used).

from ansible-for-devops.

geerlingguy avatar geerlingguy commented on August 15, 2024

It looks like everything's working now—the older version of the CentOS 7 box (which I think was running 7.0—7.1 is latest) must've had a problem with the preinstalled setuptools, which is now resolved.

I did a fresh vagrant up following the instructions in the book using the orchestration example Vagrantfile in this repo, and ran the following three commands on a fresh install:

$ ansible app -s -m yum -a "name=MySQL-python state=present"
$ ansible app -s -m yum -a "name=python-setuptools state=present"
$ ansible app -s -m easy_install -a "name=django"

Then I ran the command to check the installed version:

$ ansible -i inventory app -a "python -c 'import django; \
>     print django.get_version()'"
192.168.60.4 | SUCCESS | rc=0 >>
1.10b1

192.168.60.5 | SUCCESS | rc=0 >>
1.10b1

from ansible-for-devops.

geerlingguy avatar geerlingguy commented on August 15, 2024

Note that someone else via email noticed the same thing around March 30:

I found that easy_install was not working as expected and was generating the following error:
ImportError: No module named ssl_match_hostname
To resolve this I had to run: pip install backports.ssl_match_hostname

from ansible-for-devops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.