Ansible使用最新版本的setuptools和pip来获得virtualenv的正确方法

时间:2016-04-27 23:42:39

标签: pip virtualenv ansible

今天你好,以获得与vagrant(1.7.4)

一起运行的virtualenv

我首先使用apt ::

安装python-virtualenv
- name: Apt install
  apt: name={{ item }} state=installed update_cache=yes
  with_items:
    ## needed to make virtualenv
    - python-dev
    - python-setuptools
    - python-virtualenv

使用eassy_install我得到了pip ::

- easy_install: name=pip

我使用shell:创建了virtualenv:

- name: == Create virtualenv
  shell: virtualenv "{{ venv_name }}"
  args:
    chdir: "{{ home }}"
  sudo: true
  sudo_user: "{{ user }}"

- name: Upgrade pip wheel and setuptools
  pip: name={{ item }} virtualenv="{{ home }}/{{ venv_name }}"
       extra_args='--upgrade'
  with_items:
    - pip
    - wheel
    - setuptools

最后用pip给出了virtualenv信息::

- name: pip Install packages into virtualenv
  pip: >
    name={{ item }} virtualenv="{{ home }}/{{ venv_name }}"
    virtualenv_site_packages="no"
  with_items:
    - ansicolors
    - blist

这是使用最新版本的setuptools和pip获得virtualenv的正确方法吗?:

(venv)toto@vagrant-ubuntu-wily-64:~$ python -c "import pkg_resources as pkg; print(pkg.require(['setuptools'])[0].version)"
20.10.1
(venv)toto@vagrant-ubuntu-wily-64:~$ pip -V
pip 8.1.1 from /home/toto/venv/local/lib/python2.7/site-packages (python 2.7)
(venv)toto@vagrant-ubuntu-wily-64:~$ wheel version
wheel 0.29.0
(venv)toto@vagrant-ubuntu-wily-64:~$

2 个答案:

答案 0 :(得分:1)

您可以要求提供最新版本:

- name: Upgrade pip wheel and setuptools
  pip: name={{ item }} virtualenv="{{ home }}/{{ venv_name }}" state=latest
       extra_args='--upgrade'
  with_items:
    - pip
    - wheel
    - setuptools

- name: pip Install packages into virtualenv
  pip: >
    name={{ item }} virtualenv="{{ home }}/{{ venv_name }}" state=latest
    virtualenv_site_packages="no"
  with_items:
    - ansicolors
    - blist

答案 1 :(得分:1)

你可以尝试这个:

- name: install python packages
  pip:
    name: "{{ item.name }}"
    extra_args: "--upgrade"
    virtualenv: "{{ home }}/{{ venv_name }}"
    virtualenv_command: virtualenv
    state: latest
  with_items:
    - pip
    - wheel
    - setuptools
    - ansicolors
    - blist