cchurch.virtualenv

VirtualEnv

This role helps you set up a Python virtual environment and manage its packages. It requires Ansible version 2.8 or newer. Support for older versions has been removed as of version 0.7.0.

Requirements

  • If you use the become feature (where virtualenv_user is different from ansible_user or ansible_ssh_user), you need to have the right operating system packages installed (like sudo).
  • If none of ansible_user, ansible_ssh_user, or ansible_become_user is root, you'll need to manually install the required OS packages to use the virtualenv command before using this role.

Role Variables

Here are the variables you can set to customize the behavior of this role:

  • virtualenv_path: Where to create or update the virtual environment (required).
  • virtualenv_user: User account used to create/update the virtual environment; defaults to the current user.
  • virtualenv_default_os_packages: Default operating system packages needed; usually, no changes are needed unless using a different package manager.
  • virtualenv_os_packages: Additional OS packages to install for the virtual environment.
  • virtualenv_easy_install_packages: Python packages to install globally with easy_install.
  • virtualenv_global_packages: Python packages to install globally with pip.
  • virtualenv_requirements: List of requirement files to use for installing packages inside the virtual environment.
  • virtualenv_post_packages: Python packages to install inside the virtual environment after the requirements are processed.
  • virtualenv_recreate: Whether to delete and recreate the virtual environment; defaults to no.

You can also define a notification handler:

  • virtualenv_notify_on_updated: Name for the handler to notify when the virtual environment is created or updated.

Example Playbook

The following example playbook installs libjpeg as a system package, sets up a virtual environment, installs specific packages, manages requirements, and cleans up an old package:

- hosts: all
  roles:
    - name: cchurch.virtualenv
      vars:
        virtualenv_path: ~/env
        virtualenv_os_packages:
          apt: [libjpeg-dev]
          yum: [libjpeg-devel]
        virtualenv_pre_packages:
          - name: Django
            version: 1.11.26
          - Pillow
        virtualenv_requirements:
          - ~/src/requirements.txt
        virtualenv_post_packages:
          - name: PIL
            state: absent
  handlers:
    - name: custom virtualenv handler
      debug:
        msg: "virtualenv in {{ virtualenv_path }} was updated."
      listen: virtualenv updated

License

This role is licensed under BSD.

Author Information

Created by Chris Church (cchurch).

Informazioni sul progetto

Configure and update a Python virtualenv.

Installa
ansible-galaxy install cchurch.virtualenv
Licenza
other
Download
33.6k
Proprietario
Python/Django/Ansible, will code for sweet tea and beer.