Browse Source

installer file in eigener umgebung und anderes
der installer wird jetzt nicht mehr andauernd geloescht

Thomas Verchow 6 years ago
parent
commit
1594a7dac5
5 changed files with 75 additions and 74 deletions
  1. 1 0
      README.md
  2. 3 0
      defaults/main.yml
  3. 62 55
      tasks/main.yml
  4. 0 18
      tasks/remove.yml
  5. 9 1
      vars/main.yml

+ 1 - 0
README.md

@@ -35,6 +35,7 @@ Role Variables
 | anaconda_home_dir | no | `/opt/anaconda` | | Path to Anaconda installation. |
 | anaconda_home_dir | no | `/opt/anaconda` | | Path to Anaconda installation. |
 | anaconda_installer_uri | no | see [defaults](defaults/main.yml) | | URI to the installer file. Use `https://` for remote or `file://` for local files on the target host. The target host requires access to that file. See above for online resources. |
 | anaconda_installer_uri | no | see [defaults](defaults/main.yml) | | URI to the installer file. Use `https://` for remote or `file://` for local files on the target host. The target host requires access to that file. See above for online resources. |
 | anaconda_installer_md5 | no | see [defaults](defaults/main.yml) | | The md5 checksum of the installer file. See above for online resources. |
 | anaconda_installer_md5 | no | see [defaults](defaults/main.yml) | | The md5 checksum of the installer file. See above for online resources. |
+| anaconda_installer_dir | no | `anaconda_home_dir` | | Destination folder for downloading the installer-file. If it's not `anaconda_home_dir` it will not be removed when `state = absent`. |
 | anaconda_force_install | no | False | boolean | Run installer even if the installer-file is unchanged and Anaconda seems to be installed. |
 | anaconda_force_install | no | False | boolean | Run installer even if the installer-file is unchanged and Anaconda seems to be installed. |
 | anaconda_set_path | no | True | boolean | Adds Anaconda's path to the beginning of `$PATH` for all bash/ksh/zsh/ash login shells. See above for details. |
 | anaconda_set_path | no | True | boolean | Adds Anaconda's path to the beginning of `$PATH` for all bash/ksh/zsh/ash login shells. See above for details. |
 
 

+ 3 - 0
defaults/main.yml

@@ -16,3 +16,6 @@ anaconda_force_install: False
 
 
 # set anaconda binary path at the beginning of $PATH
 # set anaconda binary path at the beginning of $PATH
 anaconda_set_path: True
 anaconda_set_path: True
+
+# destination folder for downloaded installer-files
+anaconda_installer_dir: "{{ anaconda_home_dir }}"

+ 62 - 55
tasks/main.yml

@@ -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:
     file:
-      dest: "{{ anaconda_home_dir }}"
+      dest: "{{ item }}"
       state: directory
       state: directory
-
-  - name: download installer file exists
+    with_items:
+      - "{{ anaconda_installer_dir }}"
+      - "{{ anaconda_home_dir }}"
+  - name: pre - ensure installer file exists
     get_url:
     get_url:
       url: "{{ anaconda_installer_uri }}"
       url: "{{ anaconda_installer_uri }}"
-      dest: "{{ anaconda_home_dir }}/installer.sh"
+      dest: "{{ anaconda_installer_file }}"
+      force: False
       checksum: "md5:{{ anaconda_installer_md5 }}"
       checksum: "md5:{{ anaconda_installer_md5 }}"
     register: installer_file
     register: installer_file
-
-  - name: write warning into Anaconda home dir
+  - name: pre - write warning into Anaconda installer dir
     copy:
     copy:
-      dest: "{{ anaconda_home_dir }}/do_not_touch_installer.sh.txt"
+      dest: "{{ anaconda_installer_file }}.WARNING.txt"
       content: |
       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:
   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
     failed_when: false
     register: installer_out
     register: installer_out
-
-  - name: fail if installer finished unsuccessfully
+  - name: install - fail if installer finished unsuccessfully
     fail:
     fail:
       msg: "{{ installer_out.stderr }}"
       msg: "{{ installer_out.stderr }}"
     when: "not (('ERROR: File or directory already exists' in installer_out.stderr) or ('installation finished.' in installer_out.stdout))"
     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:
   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:
   lineinfile:
     dest: "{{ item }}"
     dest: "{{ item }}"
     create: true
     create: true
@@ -87,5 +74,25 @@
     - /etc/ksh.kshrc.local
     - /etc/ksh.kshrc.local
     - /etc/zsh.zshrc.local
     - /etc/zsh.zshrc.local
     - /etc/ash.ashrc.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

+ 0 - 18
tasks/remove.yml

@@ -1,18 +0,0 @@
----
-
-- name: remove Anaconda home dir
-  file:
-    dest: "{{ anaconda_home_dir }}"
-    state: absent
-
-- name: 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

+ 9 - 1
vars/main.yml

@@ -1,3 +1,11 @@
 ---
 ---
 
 
-anaconda_install_dir:    "{{ anaconda_home_dir }}/dist"
+# directory for installing the anaconda distribution
+# Hint: it's not anaconda_home_dir because the installer-file
+# is located there by default and (1) anaconda has to be installed
+# in a non-existing dir and (2) for a version change we have to remove
+# the installation dir without removing the installer-file.
+anaconda_install_dir: "{{ anaconda_home_dir }}/dist"
+
+# just for convenience
+anaconda_installer_file: "{{ anaconda_installer_dir }}/{{ anaconda_installer_uri|basename }}"