library/roles/python-virtualenv: Ansible 2 compatibility.

This commit is contained in:
Andrea Dell'Amico 2016-07-06 15:19:03 +02:00
parent 08ca088916
commit 41b8687fee
2 changed files with 32 additions and 38 deletions

View File

@ -5,10 +5,10 @@ py_virtenv_pkgs:
- python-pip - python-pip
- python-virtualenv - python-virtualenv
# py_virtenv_pip_pkgs: py_virtenv_pip_pkgs:
# - pip_pkg_foo -
# - pip_pkg_bar
# py_virtenv_pip_requirements: "/tmp/foo/requirements.txt" # py_virtenv_pip_requirements: "/tmp/foo/requirements.txt"
#
py_virtenv_env_base_dir: "/tmp/foo" # py_virtenv_env_base_dir: "/tmp/foo"
py_virtenv_env_base_dir:

View File

@ -1,40 +1,34 @@
--- ---
- name: Install the python virtualenv packages - block:
apt: name={{ item }} state={{ py_virtenv_pkgs_state }}
with_items: py_virtenv_pkgs - name: Install the python virtualenv packages
tags: [ "python", "py_virtenv" ] apt: name={{ item }} state={{ py_virtenv_pkgs_state }}
with_items: '{{ py_virtenv_pkgs }}'
- name: Create the virtenv environments. - name: Create the virtenv environments.
command: virtualenv {{ py_virtenv_env_base_dir }} command: virtualenv {{ py_virtenv_env_base_dir }}
tags: [ "python", "py_virtenv" ] when: '{{ py_virtenv_env_base_dir }} != ""'
- name: Install a list of pip packages inside the virtualenv, inherit the global site-packages - name: Install a list of pip packages inside the virtualenv, inherit the global site-packages
pip: name={{ item }} virtualenv={{ py_virtenv_env_base_dir }} virtualenv_site_packages=yes pip: name={{ item }} virtualenv={{ py_virtenv_env_base_dir }} virtualenv_site_packages=yes
with_items: py_virtenv_pip_pkgs with_items: '{{ py_virtenv_pip_pkgs | default ([]) }}'
when: when: py_virtenv_site
- py_virtenv_pip_pkgs is defined
- py_virtenv_site
tags: [ "python", "py_virtenv" ]
- name: Install a list of pip packages inside the virtualenv - name: Install a list of pip packages inside the virtualenv
pip: name={{ item }} virtualenv={{ py_virtenv_env_base_dir }} pip: name={{ item }} virtualenv={{ py_virtenv_env_base_dir }}
with_items: py_virtenv_pip_pkgs with_items: '{{ py_virtenv_pip_pkgs | default ([]) }}'
when: when: not py_virtenv_site
- py_virtenv_pip_pkgs is defined
- not py_virtenv_site
tags: [ "python", "py_virtenv" ]
- name: Install a list of pip packages inside the virtualenv from a requirements.txt file, inherit the global site-packages - name: Install a list of pip packages inside the virtualenv from a requirements.txt file, inherit the global site-packages
pip: requirements={{ py_virtenv_pip_requirements }} virtualenv={{ py_virtenv_env_base_dir }} virtualenv_site_packages=yes pip: requirements={{ py_virtenv_pip_requirements }} virtualenv={{ py_virtenv_env_base_dir }} virtualenv_site_packages=yes
when: when:
- py_virtenv_pip_requirements is defined - py_virtenv_pip_requirements is defined
- py_virtenv_site - py_virtenv_site
tags: [ "python", "py_virtenv" ]
- name: Install a list of pip packages inside the virtualenv from a requirements.txt file - name: Install a list of pip packages inside the virtualenv from a requirements.txt file
pip: requirements={{ py_virtenv_pip_requirements }} virtualenv={{ py_virtenv_env_base_dir }} pip: requirements={{ py_virtenv_pip_requirements }} virtualenv={{ py_virtenv_env_base_dir }}
when: when:
- py_virtenv_pip_requirements is defined - py_virtenv_pip_requirements is defined
- not py_virtenv_site - not py_virtenv_site
tags: [ "python", "py_virtenv" ]
tags: [ "python", "py_virtenv" ]