我创建了一个剧本,假设为本地开发人员运行一个
django网站.这些是组织约束
>目前VM是Centos – http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box
>机器正在通过Vagrant配置ansible.
>开发人员需要python2.7.
我试图遵循软件收集路线
>将scl repo添加到框中
>通过yum安装python27
>使用shell modoule启用python27
>在shell中创建virtualenv
新创建的virtualenv和python二进制文件在提供后会出错.这是我的剧本的相关部分:
main.yml
- hosts: app
sudo: yes
sudo_user: root
gather_facts: true
roles:
# insert other roles
tasks:
- name: Add SCL Repos
command: sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python27.repo >> /etc/yum.repos.d/scl.repo'
- name: Install python dependencies
yum: pkg={{ item }} state=present
with_items:
- "python-devel"
- "scl-utils"
- "python27"
- name: Manually create virtual .env and install requirements
shell: "source /opt/rh/python27/enable && virtualenv /vagrant/.env && source /vagrant/.env/bin/activate && pip install -r /vagrant/requirements/local.txt"
Ansible – stdout
这是我的ansible的stdout消息的尾部.
pip can't proceed with requirement 'pytz (from -r /vagrant/requirements/base.txt (line 3))' due to a pre-existing build directory.\n location: /vagrant/.env/build/pytz\nThis is likely due to a previous installation that failed.\npip is being responsible and not assuming it can delete this.\nPlease delete it and try again.\n\nCleaning up...
通过SSH进行死后测试
为了从这个问题中收集更多信息,我在盒子里砸了一下,看看我能得到什么反馈.
$vagrant ssh
Last login: Fri Feb 12 22:17:03 2016 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$cd /vagrant/
[vagrant@localhost vagrant]$source .env/bin/activate
(.env)[vagrant@localhost vagrant]$pip install -r requirements/local.txt
/vagrant/.env/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
一般来说,这种方法感觉像圆孔中的方形钉.我很想听听社区关于使用通过ansible配置的python27 virtualenv在本地运行centos盒的适当方法的一些反馈.
最佳答案 您始终可以使用ansible environment指令手动设置适当的变量,以便调用正确的可执行文件.这是一个例子:
environment:
PATH: "/opt/rh/rh-python34/root/usr/bin:{{ ansible_env.PATH }}"
LD_LIBRARY_PATH: "/opt/rh/rh-python34/root/usr/lib64"
MANPATH: "/opt/rh/rh-python34/root/usr/share/man"
XDG_DATA_DIRS: "/opt/rh/rh-python34/root/usr/share"
PKG_CONFIG_PATH: "/opt/rh/rh-python34/root/usr/lib64/pkgconfig"
pip: "virtualenv={{root_dir}}/{{venvs_dir}}/{{app_name}}_{{spec}} requirements={{root_dir}}/{{spec}}_sites/{{app_name}}/requirements.txt"