使用Chef时,'pip install -r requirements.txt'失败

时间:2016-07-20 08:10:25

标签: python pip chef

我有一个复制到Chef节点的脚本;它激活python虚拟环境,然后从需求文件中安装需求:

bash 'install_dependencies' do
        cwd '/opt/application/'
        user 'app-user'
        code <<-EOH
                ./scripts/install-deps.sh
                EOH
end

当我在本地运行时,一切都很顺利。当使用Chef执行块(bash)运行时,它会无声地失败。

Collecting bs4 (from -r requirements.txt (line 4))
  1 location(s) to search for versions of bs4:
  * https://pypi.python.org/simple/bs4/
  Getting page https://pypi.python.org/simple/bs4/
  Looking up "https://pypi.python.org/simple/bs4/" in the cache
  No cache entry available
  Starting new HTTPS connection (1): pypi.python.org
  "GET /simple/bs4/ HTTP/1.1" 200 313
  Updating cache with response from "https://pypi.python.org/simple/bs4/"
  Caching b/c date exists and max-age > 0
  Analyzing links from page https://pypi.python.org/simple/bs4/
    Found link https://pypi.python.org/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gz#md5=fe7e51587ac3b174608f3c4f8bd893ac (from https://pypi.python.org/simple/bs4/), version: 0.0.1
    Found link https://pypi.python.org/packages/50/fe/c4bf5083af20ec85ac5d278dfd12a9756724100c308b7bdccbaa7cbf5715/bs4-0.0.0.tar.gz#md5=c1b62a2b9f2987d7f949f1392a82518f (from https://pypi.python.org/simple/bs4/), version: 0.0.0
  Using version 0.0.1 (newest of versions: 0.0.0, 0.0.1)
Cleaning up...

有什么建议吗?这是失败输出:

Collecting bs4 (from -r requirements.txt (line 4))
  1 location(s) to search for versions of bs4:
  * https://pypi.python.org/simple/bs4/
  Getting page https://pypi.python.org/simple/bs4/
  Looking up "https://pypi.python.org/simple/bs4/" in the cache
  Current age based on date: 558
  Freshness lifetime from max-age: 600
  Freshness lifetime from request max-age: 600
  The response is "fresh", returning cached response
  600 > 558
  Analyzing links from page https://pypi.python.org/simple/bs4/
    Found link https://pypi.python.org/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gz#md5=fe7e51587ac3b1
    Found link https://pypi.python.org/packages/50/fe/c4bf5083af20ec85ac5d278dfd12a9756724100c308b7bdccbaa7cbf5715/bs4-0.0.0.tar.gz#md5=c1b62a2b9f2987
  Using version 0.0.1 (newest of versions: 0.0.0, 0.0.1)
  Using cached wheel link: file:///ridl/.cache/pip/wheels/84/67/d4/9e09d9d5adede2ee1c7b7e8775ba3fbb04d07c4f946f0e4f11/bs4-0.0.1-cp34-none-any.whl
Collecting requests (from -r requirements.txt (line 5))
  1 location(s) to search for versions of requests:
  * https://pypi.python.org/simple/requests/
  Getting page https://pypi.python.org/simple/requests/
  Looking up "https://pypi.python.org/simple/requests/" in the cache
  Current age based on date: 558
  Freshness lifetime from max-age: 600
  Freshness lifetime from request max-age: 600
  The response is "fresh", returning cached response
  600 > 558
  Analyzing links from page https://pypi.python.org/simple/requests/
    Found link https://pypi.python.org/packages/00/c8/8cf0f078100ce5fe7ff35927d8861e2e36daed9be2db56690f3ad80ccec4/requests-0.7.1.tar.gz#md5=4821c6902
    Found link https://pypi.python.org/packages/01/44/39988315e036b79fe70428273053617266bf20d1363e91082346fae8450d/requests-0.10.3.tar.gz#md5=a055af00
    Found link https://pypi.python.org/packages/01/da/da83c242c5a77c58aa86072d68fd2855aa9b4d3b1a8bac4b402531b25ff1/requests-0.13.9.tar.gz#md5=66d52b8f
    Found link https://pypi.python.org/packages/02/56/a6203485b552f9e8e8f16bd4e576446f94737ccbc563957e7510c8e401e4/requests-0.13.6.tar.gz#md5=9ea0f38c

来自(成功)本地运行的输出头 - 即继续完成安装:

index.html

2 个答案:

答案 0 :(得分:2)

您还可以使用pip_requirements食谱中的poise-python资源,该资源会为您完成所有这些。

答案 1 :(得分:0)

看起来Chef的bash块没有为它所代表的用户设置主目录。因此,pip无法找到/使​​用缓存目录。在脚本中明确说明它解决了问题:

$props = @{
    'Title'          = $update.Update.Title
    'Classification' = $update.Classification
    'Approved'       = $update.Approved
}