|
@@ -1,81 +1,68 @@
|
|
|
---
|
|
|
-# pre installation tasks
|
|
|
-# ======================
|
|
|
|
|
|
-- name: check var anaconda_state
|
|
|
- fail:
|
|
|
- msg: "anaconda_state '{{ anaconda_state }}' not supported. Use 'present' or 'absent'."
|
|
|
- when: anaconda_state != "present" and anaconda_state != "absent"
|
|
|
-
|
|
|
-- block:
|
|
|
+- name: pre tasks
|
|
|
+# ===============
|
|
|
+ when: "anaconda_state == 'present'"
|
|
|
|
|
|
- - name: ensure home dir exists
|
|
|
+ block:
|
|
|
+ - name: pre - ensure folders exist
|
|
|
file:
|
|
|
- dest: "{{ anaconda_home_dir }}"
|
|
|
+ dest: "{{ item }}"
|
|
|
state: directory
|
|
|
-
|
|
|
- - name: download installer file exists
|
|
|
+ with_items:
|
|
|
+ - "{{ anaconda_installer_dir }}"
|
|
|
+ - "{{ anaconda_home_dir }}"
|
|
|
+ - name: pre - ensure installer file exists
|
|
|
get_url:
|
|
|
url: "{{ anaconda_installer_uri }}"
|
|
|
- dest: "{{ anaconda_home_dir }}/installer.sh"
|
|
|
+ dest: "{{ anaconda_installer_file }}"
|
|
|
+ force: False
|
|
|
checksum: "md5:{{ anaconda_installer_md5 }}"
|
|
|
register: installer_file
|
|
|
-
|
|
|
- - name: write warning into Anaconda home dir
|
|
|
+ - name: pre - write warning into Anaconda installer dir
|
|
|
copy:
|
|
|
- dest: "{{ anaconda_home_dir }}/do_not_touch_installer.sh.txt"
|
|
|
+ dest: "{{ anaconda_installer_file }}.WARNING.txt"
|
|
|
content: |
|
|
|
- Do not touch the installer.sh file because ansible uses
|
|
|
- it to decide if a reinstallation (uninstall/install) is
|
|
|
- necessary.
|
|
|
-
|
|
|
- - name: check if Anaconda is already installed
|
|
|
- stat:
|
|
|
- path: "{{ anaconda_install_dir }}/bin/conda"
|
|
|
- register: conda_binary
|
|
|
-
|
|
|
- when: "anaconda_state == 'present'"
|
|
|
+ Do not touch the file because ansible
|
|
|
+ may use it to decide if a reinstallation
|
|
|
+ (uninstall/install) is necessary.
|
|
|
+ - name: pre - remove installation for a new install
|
|
|
+ # if the installer file changes, we assume a new version should be installed
|
|
|
+ # (the Anaconda way recommend a 'conda update' or similar instead of a new
|
|
|
+ # installation but we won't to that here to keep it simple stupid)
|
|
|
+ when: installer_file|changed
|
|
|
+ file:
|
|
|
+ dest: "{{ anaconda_install_dir }}"
|
|
|
+ state: absent
|
|
|
|
|
|
rescue:
|
|
|
- - name: failed to prepare installation
|
|
|
- fail:
|
|
|
- msg: "leave installed Anaconda (if any) untouched, installer file may be changed"
|
|
|
+ - fail:
|
|
|
+ msg: "failed to prepare installation. installer file may be changed. a pre-installed anaconda may be removed."
|
|
|
|
|
|
-# uninstall
|
|
|
-# =========
|
|
|
-# if the installer file changes, we assume a new version should be installed
|
|
|
-# (the Anaconda way recommend a 'conda update' or similar instead of a new
|
|
|
-# installation but we won't to that here to kiss)
|
|
|
-- include: remove.yml
|
|
|
- when: (installer_file|changed and conda_binary.stat.exists) or anaconda_state == 'absent'
|
|
|
|
|
|
+- name: install
|
|
|
+# =============
|
|
|
+ when: "anaconda_state == 'present' and (installer_file|changed or anaconda_force_install)"
|
|
|
|
|
|
-# install
|
|
|
-# =======
|
|
|
-- block:
|
|
|
-
|
|
|
- - name: run installer
|
|
|
- command: "bash installer.sh -b -p {{ anaconda_install_dir }} {{ anaconda_force_install|ternary('-f', '') }}"
|
|
|
- args:
|
|
|
- chdir: "{{ anaconda_home_dir }}"
|
|
|
+ block:
|
|
|
+ - name: install - run installer
|
|
|
+ command: "bash {{ anaconda_installer_file }} -b -p {{ anaconda_install_dir }} {{ anaconda_force_install|ternary('-f', '') }}"
|
|
|
failed_when: false
|
|
|
register: installer_out
|
|
|
-
|
|
|
- - name: fail if installer finished unsuccessfully
|
|
|
+ - name: install - fail if installer finished unsuccessfully
|
|
|
fail:
|
|
|
msg: "{{ installer_out.stderr }}"
|
|
|
when: "not (('ERROR: File or directory already exists' in installer_out.stderr) or ('installation finished.' in installer_out.stdout))"
|
|
|
|
|
|
- when: "anaconda_state == 'present' and (installer_file|changed or anaconda_force_install)"
|
|
|
-
|
|
|
rescue:
|
|
|
- - name: rollback installation
|
|
|
- include: remove.yml
|
|
|
- - fail: msg="Installation failed! Rolled back installation!"
|
|
|
+ - fail:
|
|
|
+ msg: "Installation failed!"
|
|
|
+
|
|
|
+
|
|
|
+- name: post task - set path to anaconda
|
|
|
+# ===============
|
|
|
+ when: "anaconda_state == 'present' and anaconda_set_path|bool"
|
|
|
|
|
|
-# post install tasks
|
|
|
-# ==================
|
|
|
-- name: set path to anaconda
|
|
|
lineinfile:
|
|
|
dest: "{{ item }}"
|
|
|
create: true
|
|
@@ -87,5 +74,25 @@
|
|
|
- /etc/ksh.kshrc.local
|
|
|
- /etc/zsh.zshrc.local
|
|
|
- /etc/ash.ashrc.local
|
|
|
- when: "anaconda_state == 'present' and anaconda_set_path|bool"
|
|
|
|
|
|
+
|
|
|
+- name: uninstall
|
|
|
+# ===============
|
|
|
+ when: anaconda_state == 'absent'
|
|
|
+
|
|
|
+ block:
|
|
|
+ - name: uninstall - remove Anaconda home dir
|
|
|
+ file:
|
|
|
+ dest: "{{ anaconda_home_dir }}"
|
|
|
+ state: absent
|
|
|
+ - name: uninstall - remove path to anaconda
|
|
|
+ lineinfile:
|
|
|
+ dest: "{{ item }}"
|
|
|
+ create: true
|
|
|
+ state: absent
|
|
|
+ line: 'export PATH="{{ anaconda_install_dir }}/bin:$PATH"'
|
|
|
+ with_items:
|
|
|
+ - /etc/bash.bashrc.local
|
|
|
+ - /etc/ksh.kshrc.local
|
|
|
+ - /etc/zsh.zshrc.local
|
|
|
+ - /etc/ash.ashrc.local
|