首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当试图使用ansible在虚拟主机内安装时拒绝权限

当试图使用ansible在虚拟主机内安装时拒绝权限
EN

Stack Overflow用户
提问于 2015-04-16 07:30:05
回答 4查看 5.4K关注 0票数 6

我把这出戏写在我的剧本里了

代码语言:javascript
复制
- name: Setup virtualenv
  pip: 
    requirements="/vagrant/webapp/requirements/{{ requirements_filename }}" 
    virtualenv="$HOME/.envs/{{ project_name }}"

但是,我收到了一个权限被拒绝的错误。看来ansible正在尝试将包安装到系统路径中,而不是虚拟环境中。

以下是完整的回溯:

代码语言:javascript
复制
TASK: [deploy | Setup virtualenv] ********************************************* 
failed: [default] => {"cmd": "/usr/bin/pip install -r /vagrant/webapp/requirements/dev.txt", "failed": true}
msg: stdout: New python executable in /home/vagrant/.envs/venv/bin/python
Installing setuptools, pip...done.
Downloading/unpacking django>=1.8 (from -r /vagrant/webapp/requirements/requirements.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): wsgiref>=0.1.2 in /usr/lib/python2.7 (from -r /vagrant/webapp/requirements/requirements.txt (line 4))
Downloading/unpacking django-allauth>=0.19.1 (from -r /vagrant/webapp/requirements/requirements.txt (line 5))
  Running setup.py (path:/tmp/pip_build_vagrant/django-allauth/setup.py) egg_info for package django-allauth

Downloading/unpacking psycopg2>=2.6 (from -r /vagrant/webapp/requirements/requirements.txt (line 6))
  Running setup.py (path:/tmp/pip_build_vagrant/psycopg2/setup.py) egg_info for package psycopg2

Downloading/unpacking django-currencies>=0.3.3 (from -r /vagrant/webapp/requirements/requirements.txt (line 7))
  Downloading django-currencies-0.3.3.tar.gz
  Running setup.py (path:/tmp/pip_build_vagrant/django-currencies/setup.py) egg_info for package django-currencies

Downloading/unpacking django-countries>=3.2 (from -r /vagrant/webapp/requirements/requirements.txt (line 8))
  Running setup.py (path:/tmp/pip_build_vagrant/django-countries/setup.py) egg_info for package django-countries

Downloading/unpacking stripe>=1.22.1 (from -r /vagrant/webapp/requirements/requirements.txt (line 9))
  Running setup.py (path:/tmp/pip_build_vagrant/stripe/setup.py) egg_info for package stripe

Downloading/unpacking pillow>=2.8.0 (from -r /vagrant/webapp/requirements/requirements.txt (line 10))
  Running setup.py (path:/tmp/pip_build_vagrant/pillow/setup.py) egg_info for package pillow
    Single threaded build, not installing mp_compile: 1 processes

    warning: no files found matching 'LICENSE' under directory 'docs'
Downloading/unpacking django-compressor>=1.4 (from -r /vagrant/webapp/requirements/requirements.txt (line 11))
Downloading/unpacking djangorestframework>=3.1.1 (from -r /vagrant/webapp/requirements/requirements.txt (line 12))
Downloading/unpacking django-filter>=0.9.2 (from -r /vagrant/webapp/requirements/requirements.txt (line 13))
  Downloading django_filter-0.9.2-py2.py3-none-any.whl
Obtaining formtools from git+https://github.com/django/django-formtools.git#egg=formtools (from -r /vagrant/webapp/requirements/requirements.txt (line 14))
  Cloning https://github.com/django/django-formtools.git to ./src/formtools
  Running setup.py (path:/tmp/src/formtools/setup.py) egg_info for package formtools

  Installing extra requirements: 'egg'
Downloading/unpacking django-widget-tweaks>=1.3 (from -r /vagrant/webapp/requirements/requirements.txt (line 15))
  Downloading django-widget-tweaks-1.3.tar.gz
  Running setup.py (path:/tmp/pip_build_vagrant/django-widget-tweaks/setup.py) egg_info for package django-widget-tweaks

Downloading/unpacking django-braces>=1.4.0 (from -r /vagrant/webapp/requirements/requirements.txt (line 16))
  Downloading django_braces-1.4.0-py2.py3-none-any.whl
Downloading/unpacking django-debug-toolbar>=1.3.0 (from -r /vagrant/webapp/requirements/dev.txt (line 4))
Downloading/unpacking python-openid>=2.2.5 (from django-allauth>=0.19.1->-r /vagrant/webapp/requirements/requirements.txt (line 5))
  Running setup.py (path:/tmp/pip_build_vagrant/python-openid/setup.py) egg_info for package python-openid

    warning: no files found matching 'CHANGELOG'
    warning: no files found matching '*.css' under directory 'doc'
    warning: no files found matching '*.html' under directory 'doc'
Downloading/unpacking requests-oauthlib>=0.3.0 (from django-allauth>=0.19.1->-r /vagrant/webapp/requirements/requirements.txt (line 5))
  Downloading requests_oauthlib-0.4.2-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): requests>=1.0.3 in /usr/lib/python2.7/dist-packages (from django-allauth>=0.19.1->-r /vagrant/webapp/requirements/requirements.txt (line 5))
Downloading/unpacking django-appconf>=0.4 (from django-compressor>=1.4->-r /vagrant/webapp/requirements/requirements.txt (line 11))
  Downloading django_appconf-1.0.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from django-braces>=1.4.0->-r /vagrant/webapp/requirements/requirements.txt (line 16))
Downloading/unpacking sqlparse (from django-debug-toolbar>=1.3.0->-r /vagrant/webapp/requirements/dev.txt (line 4))
  Running setup.py (path:/tmp/pip_build_vagrant/sqlparse/setup.py) egg_info for package sqlparse

Downloading/unpacking oauthlib>=0.6.2 (from requests-oauthlib>=0.3.0->django-allauth>=0.19.1->-r /vagrant/webapp/requirements/requirements.txt (line 5))
  Running setup.py (path:/tmp/pip_build_vagrant/oauthlib/setup.py) egg_info for package oauthlib

Installing collected packages: django, django-allauth, psycopg2, django-currencies, django-countries, stripe, pillow, django-compressor, djangorestframework, django-filter, formtools, django-widget-tweaks, django-braces, django-debug-toolbar, python-openid, requests-oauthlib, django-appconf, sqlparse, oauthlib
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 671, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 901, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
    os.makedirs(destsubdir)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/Django-1.8.dist-info'

Storing debug log for failure in /home/vagrant/.pip/pip.log


FATAL: all hosts have already failed -- aborting
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-04-17 00:51:45

我通过显式设置路径而不是使用$HOME变量来解决这个问题。

代码语言:javascript
复制
- name: Setup virtualenv
  pip:
    virtualenv="/home/vagrant/.envs/{{ project_name }}"
    requirements="/vagrant/webapp/requirements/{{ requirements_filename }}"
票数 4
EN

Stack Overflow用户

发布于 2015-04-16 07:33:19

还可以尝试指定一个pip可执行路径:

代码语言:javascript
复制
executable="$HOME/.envs/{{ project_name }}/bin/pip"

没有搜索TBH的确切原因,但必须做同样的事情才能将内容安装到虚拟环境中。似乎它试图使用全局pip安装到虚拟环境中。也许在某些情况下这是可能的,这不是我的案子。

票数 2
EN

Stack Overflow用户

发布于 2015-04-17 03:41:54

pip模块似乎正在使用系统Python,因此它将尝试在预期的系统路径上安装到site-packages,并且由于您没有以root用户身份运行这个包或使用sudo,所以它不能写到‘/usr/local/lib/Python 2.7/.’

我假设您想要安装虚拟环境下的pip包,对吗?

如果是这样的话,除非您设置了ansible_python_interpreter,否则默认情况下,Ansible模块总是使用系统默认的Python解释器。如何做到这一点的示例可以在在远程计算机上始终在虚拟主机中运行ansible的最佳方法?上找到。

可以找到一个链接,链接到关于这个主题的简短讨论,以及为什么Ansible用户不想将#!/usr/bin/python更改为更支持虚拟化的#!/usr/bin/env python

请注意,如果您从本地虚拟主机运行Ansible,并尝试使用ec2模块,而没有在系统级别安装boto (但安装在virtualenv级别),您就会遇到同样的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29668129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档