main.yml 2.9 KB

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