--- - name: pre tasks # =============== when: "anaconda_state == 'present'" block: - name: pre - ensure folders exist file: dest: "{{ item }}" state: directory with_items: - "{{ anaconda_installer_dir }}" - "{{ anaconda_home_dir }}" - name: pre - ensure installer file exists get_url: url: "{{ anaconda_installer_uri }}" dest: "{{ anaconda_installer_file }}" force: False checksum: "md5:{{ anaconda_installer_md5 }}" - name: pre - link installer file to anaconda home file: src: "{{ anaconda_installer_file }}" dest: "{{ anaconda_home_dir }}/installer.sh" state: link register: installer - name: pre - write a note for installer copy: dest: "{{ anaconda_home_dir }}/installer.README.txt" content: | Do not touch the linked file because ansible uses 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|changed file: dest: "{{ anaconda_install_dir }}" state: absent rescue: - fail: msg: "failed to prepare installation. installer file may be changed. a pre-installed anaconda may be removed." - name: install # ============= when: "anaconda_state == 'present' and (installer|changed or anaconda_force_install)" block: - name: install - run installer command: "bash {{ anaconda_home_dir }}/installer.sh -b -p {{ anaconda_install_dir }} {{ anaconda_force_install|ternary('-f', '') }}" failed_when: false register: installer_out - 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))" rescue: - fail: msg: "Installation failed!" - name: post tasks # ================ when: "anaconda_state == 'present' and anaconda_set_path|bool" block: - name: post - 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 - name: post - install pip packages pip: name: "{{ anaconda_pip_packages }}" state: latest executable: /opt/anaconda/dist/bin/pip - 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