这是我的清单的一个片段(基于这个模块:https://github.com/stankevich/puppet-python):
python::virtualenv { $virtualenv_dir:
ensure => present,
version => 'system',
systempkgs => false,
distribute => false,
owner => $user,
group => $group,
}
我第一次运行 puppet apply 时一切正常。但第二次就失败了:
Already using interpreter /usr/bin/python
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 3, in
virtualenv.main()
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
never_download=options.never_download)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1039, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1274, in install_python
shutil.copyfile(executable, py_executable)
File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 26] Text file busy: '/usr/local/myapp/venv/bin/python'
这可能是因为我有一堆使用来自 virtualenv 的 Python 二进制文件(Celery 工作者、uwsgi 工作者等)运行的后台进程。
有没有办法只在第一次初始化虚拟环境?创建目录后就不需要运行虚拟环境命令了,对吗?
答案1
以下类将创建一个虚拟环境。“creates”限制命令仅在虚拟环境不存在时运行
class virtualenv ( $virtualenv_dir ) {
package{'python-virtualenv':
ensure => installed,
}
exec{'create_virtualenv':
creates => $virtualenv_dir,
command => "virtualenv $virtualen_dir",
require => Package['python-virtualenv'],
}
}
使用以下命令调用该类:
class {'virtualenv':
virtualenv_dir => '/path/to/virtualenv',
}