Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install method (like pip) #9

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
matrix:
include:
- distro: debian10
ansible-version: '>=9, <10'
- distro: debian11
- distro: debian12
- distro: ubuntu1804
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Set up (the latest version of) virtualenv(wrapper) in Debian-like systems.

#### Variables

* `virtualenv_python_version_major` [default: `2`]: Python version to install `supervisor` for.
* `virtualenv_python_version_major` [default: `3`]: Python version to install `virtualenv` for.
* `virtualenv_python_version` [default: `virtualenv_python_version`]: Deprecated

## Dependencies
Expand Down
6 changes: 5 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# defaults file
---
virtualenv_python_version_major: 2
virtualenv_install_method: native
# Only available for < 24.04
# virtualenv_install_method: pip

virtualenv_python_version_major: 3
virtualenv_python_version: "{{ virtualenv_python_version_major }}"
10 changes: 10 additions & 0 deletions tasks/install-native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# tasks file
---
- name: install | native | install dependencies

Check warning on line 3 in tasks/install-native.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.apt:
name: "{{ virtualenv_install_native_apt_dependencies }}"
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
tags:
- virtualenv-install-native-install
18 changes: 18 additions & 0 deletions tasks/install-pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# tasks file
---
- name: install | pip | install dependencies

Check warning on line 3 in tasks/install-pip.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.apt:
name: "{{ virtualenv_install_get_pip_apt_dependencies }}"
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
tags:
- virtualenv-install-pip-dependencies

- name: install | pip | install (latest) # noqa package-latest

Check warning on line 12 in tasks/install-pip.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.pip:
name: "{{ virtualenv_install_get_pip_pip_dependencies }}"
state: latest
executable: "pip{{ virtualenv_python_version_major | string }}"
tags:
- virtualenv-install-pip-install
30 changes: 17 additions & 13 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# tasks file
---
- name: install dependencies
ansible.builtin.apt:
name: "{{ virtualenv_dependencies }}"
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
- name: install | native

Check warning on line 3 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.import_tasks: install-native.yml
when: virtualenv_install_method == 'native'
tags:
- configuration
- virtualenv
- virtualenv-install
- virtualenv-install-dependencies
- virtualenv-install-native

- name: install | pip

Check warning on line 11 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.import_tasks: install-pip.yml
when: virtualenv_install_method == 'pip'
tags:
- configuration
- virtualenv
- virtualenv-install-pip

- name: install # noqa package-latest
ansible.builtin.pip:
name: "{{ virtualenv_pip_dependencies }}"
state: latest
executable: "pip{{ virtualenv_python_version_major | string }}"
- name: verify

Check warning on line 19 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.command: >
virtualenv --version
changed_when: false
tags:
- configuration
- virtualenv
- virtualenv-install
- virtualenv-install-verify
49 changes: 26 additions & 23 deletions tests/tasks/pre.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# pre test file
---
- name: pip | check
ansible.builtin.shell: >
which pip
register: _pip_installed
changed_when: false
check_mode: false
failed_when: false

- name: pip | install
when: _pip_installed.rc != 0
- name: pip
when: virtualenv_install_method == 'pip'
block:
- name: dependencies | install
ansible.builtin.apt:
name:
- "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}"
- curl
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"

- name: pip | install # noqa command-instead-of-module
- name: pip | check
ansible.builtin.shell: >
curl -sL {{ virtualenv_get_pip_url }} | python{{ virtualenv_python_version_major | string }} -
which pip
register: _pip_installed
changed_when: false
tags:
- skip_ansible_lint
check_mode: false
failed_when: false

- name: pip | install
when: _pip_installed.rc != 0
block:
- name: dependencies | install
ansible.builtin.apt:
name:
- "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}"
- curl
state: "{{ apt_install_state | default('latest') }}"
update_cache: true
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"

- name: pip | install # noqa command-instead-of-module
ansible.builtin.shell: >
curl -sL {{ virtualenv_get_pip_url }} | python{{ virtualenv_python_version_major | string }} -
changed_when: false
tags:
- skip_ansible_lint
3 changes: 2 additions & 1 deletion tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# test file
---
- hosts: localhost
- name: converge
hosts: localhost
connection: local
become: true
pre_tasks:
Expand Down
3 changes: 2 additions & 1 deletion tests/vagrant.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# test file
---
- hosts: all
- name: converge
hosts: all
remote_user: vagrant
become: true
pre_tasks:
Expand Down
4 changes: 0 additions & 4 deletions tests/vars/_bionic.yml

This file was deleted.

4 changes: 0 additions & 4 deletions tests/vars/_buster.yml

This file was deleted.

3 changes: 1 addition & 2 deletions tests/vars/_default.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# vars file
---
virtualenv_python_version_major: 3
virtualenv_get_pip_url: 'https://bootstrap.pypa.io/pip/get-pip.py'
virtualenv_install_method: pip
3 changes: 3 additions & 0 deletions tests/vars/_noble.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# vars file
---
virtualenv_install_method: native
8 changes: 6 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# vars file
---
virtualenv_dependencies:
virtualenv_install_native_apt_dependencies:
- "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}-virtualenv"
- "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}-virtualenvwrapper"

virtualenv_install_get_pip_apt_dependencies:
- "python{{ virtualenv_python_version_major is version('3', '>=') | ternary('3', '') }}"

virtualenv_pip_dependencies:
virtualenv_install_get_pip_pip_dependencies:
- virtualenv
- virtualenvwrapper
Loading