Skip to content

Commit

Permalink
Add conda_force_recreate variable
Browse files Browse the repository at this point in the history
  • Loading branch information
breuleux committed Mar 11, 2024
1 parent fc15571 commit eca9c12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ The following variables can/must be set in the inventory:
* `app_repo`: Path to the application repository.
* If the repo is private, you should set `app_ssh_key` to a private key that is authorized to read the repo (use the SSH URL for the repo), or set `app_ssh_key_path` to the path to the proper file on the host.
* `app_tag`: Tag or branch of the `app_repo` to checkout.
* `python_version`: Python version to use.
* `python_version`: Python version to use. (If changed, set `conda_force_recreate` to true the next time the role is executed).
* `conda_version`: Conda version to use. See the list [here](https://repo.anaconda.com/miniconda). Put the part of the name that's in between `Miniconda3` and `.sh`, e.g. `latest-Linux-aarch64` or `py311_23.10.0-1-Linux-x86_64`. Make sure it's the right architecture.
* `conda_force_recreate`: If true, any existing conda environment will be wiped out and dependencies will be reinstalled from scratch. You have to set this to true when changing the Python version.


## Defining a service
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ app_code_dir: "{{ app_dir }}/code"

conda_isolate: false
conda_base: "{{ app_dir if conda_isolate else global_app_root }}/miniconda3"
conda_force_recreate: false

app_config_dir: "{{ app_dir }}/config"
app_config: "{{ app_config_dir }}/config.yaml"
Expand Down
5 changes: 5 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
accept_hostkey: yes
key_file: "{{ app_ssh_key_path }}"

- name: Remove existing conda environment if requested
ansible.builtin.command:
cmd: "{{ conda_base }}/bin/conda remove --name {{ app_name }} --all --force -y"
when: conda_force_recreate

- name: Create a conda environment
ansible.builtin.command:
cmd: "{{ conda_base }}/bin/conda create --name {{ app_name }} python={{ python_version }} --force -y"
Expand Down

0 comments on commit eca9c12

Please sign in to comment.