You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.4 KiB

  1. ---
  2. - name: Check if the correct version of Python is already installed
  3. stat:
  4. path: /usr/local/bin/python{{ python_version }}
  5. register: python_binary
  6. - name: Download and install Python
  7. when: not python_binary.stat.exists
  8. block:
  9. - name: Download Python source code
  10. get_url:
  11. dest: /tmp/python.tar.gz
  12. url: https://www.python.org/ftp/python/{{ python_full_version }}/Python-{{ python_full_version }}.tgz
  13. checksum: sha256:e0fbd5b6e1ee242524430dee3c91baf4cbbaba4a72dd1674b90fda87b713c7ab
  14. - name: Create temp directory to extract Python to
  15. file:
  16. path: /tmp/python
  17. state: directory
  18. - name: Extract Python
  19. unarchive:
  20. remote_src: true
  21. src: /tmp/python.tar.gz
  22. dest: /tmp/python
  23. extra_opts:
  24. - --strip-components=1
  25. - name: Install build dependencies for Python
  26. apt:
  27. name:
  28. - make
  29. - build-essential
  30. - libssl-dev
  31. - zlib1g-dev
  32. - libbz2-dev
  33. - libreadline-dev
  34. - libsqlite3-dev
  35. - wget
  36. - curl
  37. - llvm
  38. - libncurses5-dev
  39. - libncursesw5-dev
  40. - xz-utils
  41. - tk-dev
  42. - name: Build and install Python (this can take a long time)
  43. shell:
  44. chdir: /tmp/python
  45. cmd: |
  46. ./configure --enable-optimizations --with-ensurepip=install
  47. make
  48. make altinstall
  49. - name: Create dir for venvs
  50. file:
  51. path: /opt/venvs
  52. state: directory
  53. owner: "{{ app_username }}"
  54. group: "{{ app_username }}"
  55. mode: 0755
  56. - name: Install packages needed for compiling psycopg2
  57. apt:
  58. name:
  59. - gcc
  60. - libpq-dev
  61. - name: Create venv
  62. become_user: "{{ app_username }}"
  63. command:
  64. cmd: python{{ python_version }} -m venv {{ venv_dir }}
  65. creates: "{{ venv_dir }}"
  66. - name: Check installed packages in venv
  67. command:
  68. cmd: "{{ bin_dir }}/pip freeze"
  69. register: pip_freeze
  70. changed_when: false
  71. - name: Install Python packages into venv
  72. become_user: "{{ app_username }}"
  73. pip:
  74. executable: "{{ bin_dir }}/pip"
  75. requirements: "{{ app_dir }}/{{ pip_requirements_filename }}"
  76. - name: Install Tildes into venv as editable
  77. become_user: "{{ app_username }}"
  78. pip:
  79. executable: "{{ bin_dir }}/pip"
  80. name: "{{ app_dir }}"
  81. editable: true
  82. when: "'-e '+app_dir not in pip_freeze.stdout_lines"