main.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. - name: pre - link installer file to anaconda home
  20. file:
  21. src: "{{ anaconda_installer_file }}"
  22. dest: "{{ anaconda_home_dir }}/installer.sh"
  23. state: link
  24. register: installer
  25. - name: pre - write a note for installer
  26. copy:
  27. dest: "{{ anaconda_home_dir }}/installer.README.txt"
  28. content: |
  29. Do not touch the linked file because ansible
  30. uses it to decide if a reinstallation
  31. (uninstall/install) is necessary.
  32. - name: pre - remove installation for a new install
  33. # if the installer file changes, we assume a new version should be installed
  34. # (the Anaconda way recommend a 'conda update' or similar instead of a new
  35. # installation but we won't to that here to keep it simple stupid)
  36. when: installer|changed
  37. file:
  38. dest: "{{ anaconda_install_dir }}"
  39. state: absent
  40. rescue:
  41. - fail:
  42. msg: "failed to prepare installation. installer file may be changed. a pre-installed anaconda may be removed."
  43. - name: install
  44. # =============
  45. when: "anaconda_state == 'present' and (installer|changed or anaconda_force_install)"
  46. block:
  47. - name: install - run installer
  48. command: "bash {{ anaconda_home_dir }}/installer.sh -b -p {{ anaconda_install_dir }} {{ anaconda_force_install|ternary('-f', '') }}"
  49. failed_when: false
  50. register: installer_out
  51. - name: install - 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. rescue:
  56. - fail:
  57. msg: "Installation failed!"
  58. - name: post tasks
  59. # ================
  60. when: "anaconda_state == 'present' and anaconda_set_path|bool"
  61. block:
  62. - name: post - 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. - name: post - install pip packages
  75. pip:
  76. name: "{{ anaconda_pip_packages }}"
  77. state: latest
  78. executable: /opt/anaconda/dist/bin/pip
  79. - name: uninstall
  80. # ===============
  81. when: anaconda_state == 'absent'
  82. block:
  83. - name: uninstall - remove Anaconda home dir
  84. file:
  85. dest: "{{ anaconda_home_dir }}"
  86. state: absent
  87. - name: uninstall - remove path to anaconda
  88. lineinfile:
  89. dest: "{{ item }}"
  90. create: true
  91. state: absent
  92. line: 'export PATH="{{ anaconda_install_dir }}/bin:$PATH"'
  93. with_items:
  94. - /etc/bash.bashrc.local
  95. - /etc/ksh.kshrc.local
  96. - /etc/zsh.zshrc.local
  97. - /etc/ash.ashrc.local