main.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ---
  2. # pre installation tasks
  3. # ======================
  4. - name: check var anaconda_state
  5. fail:
  6. msg: "anaconda_state '{{ anaconda_state }}' not supported. Use 'present' or 'absent'."
  7. when: anaconda_state != "present" and anaconda_state != "absent"
  8. - block:
  9. - name: ensure home dir exists
  10. file:
  11. dest: "{{ anaconda_home_dir }}"
  12. state: directory
  13. - name: download installer file exists
  14. get_url:
  15. url: "{{ anaconda_installer_uri }}"
  16. dest: "{{ anaconda_home_dir }}/installer.sh"
  17. checksum: "md5:{{ anaconda_installer_md5 }}"
  18. register: installer_file
  19. - name: write warning into Anaconda home dir
  20. copy:
  21. dest: "{{ anaconda_home_dir }}/do_not_touch_installer.sh.txt"
  22. content: |
  23. Do not touch the installer.sh file because ansible uses
  24. it to decide if a reinstallation (uninstall/install) is
  25. necessary.
  26. - name: check if Anaconda is already installed
  27. stat:
  28. path: "{{ anaconda_install_dir }}/bin/conda"
  29. register: conda_binary
  30. when: "anaconda_state == 'present'"
  31. rescue:
  32. - name: failed to prepare installation
  33. fail:
  34. msg: "leave installed Anaconda (if any) untouched, installer file may be changed"
  35. # uninstall
  36. # =========
  37. # if the installer file changes, we assume a new version should be installed
  38. # (the Anaconda way recommend a 'conda update' or similar instead of a new
  39. # installation but we won't to that here to kiss)
  40. - include: remove.yml
  41. when: (installer_file|changed and conda_binary.stat.exists) or anaconda_state == 'absent'
  42. # install
  43. # =======
  44. - block:
  45. - name: run installer
  46. command: "bash installer.sh -b -p {{ anaconda_install_dir }} {{ anaconda_force_install|ternary('-f', '') }}"
  47. args:
  48. chdir: "{{ anaconda_home_dir }}"
  49. failed_when: false
  50. register: installer_out
  51. - name: fail if installer finished unsuccessfully
  52. fail:
  53. msg: "{{ installer_out.stderr }}"
  54. when: "not (('ERROR: File or directory already exists' in installer_out.stderr) or ('installation finished.' in installer_out.stdout))"
  55. when: "anaconda_state == 'present' and (installer_file|changed or anaconda_force_install)"
  56. rescue:
  57. - name: rollback installation
  58. include: remove.yml
  59. - fail: msg="Installation failed! Rolled back installation!"
  60. # post install tasks
  61. # ==================
  62. - name: set path to anaconda
  63. lineinfile:
  64. dest: "{{ item }}"
  65. create: true
  66. state: present
  67. insertafter: EOF
  68. line: 'export PATH="{{ anaconda_install_dir }}/bin:$PATH"'
  69. with_items:
  70. - /etc/bash.bashrc.local
  71. - /etc/ksh.kshrc.local
  72. - /etc/zsh.zshrc.local
  73. - /etc/ash.ashrc.local
  74. when: "anaconda_state == 'present' and anaconda_set_path|bool"