--- # 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: ensure home dir exists file: dest: "{{ anaconda_home_dir }}" state: directory - name: download installer file exists get_url: url: "{{ anaconda_installer_uri }}" dest: "{{ anaconda_home_dir }}/installer.sh" checksum: "md5:{{ anaconda_installer_md5 }}" register: installer_file - name: write warning into Anaconda home dir copy: dest: "{{ anaconda_home_dir }}/do_not_touch_installer.sh.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'" rescue: - name: failed to prepare installation fail: msg: "leave installed Anaconda (if any) untouched, installer file may be changed" # 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' # install # ======= - block: - name: run installer command: "bash installer.sh -b -p {{ anaconda_install_dir }} {{ anaconda_force_install|ternary('-f', '') }}" args: chdir: "{{ anaconda_home_dir }}" failed_when: false register: installer_out - name: 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!" # post install tasks # ================== - name: set path to anaconda lineinfile: dest: "{{ item }}" create: true state: present insertafter: EOF 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 when: "anaconda_state == 'present' and anaconda_set_path|bool"