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.

63 lines
1.9 KiB

  1. ---
  2. - name: Install requirements for building psycopg2 (needed by Ansible)
  3. apt:
  4. name:
  5. - gcc
  6. - libpq-dev
  7. - python3-dev
  8. - name: Install packages needed by Ansible community plugins
  9. pip:
  10. executable: pip3
  11. break_system_packages: true
  12. name:
  13. - ipaddress
  14. - psycopg2
  15. - name: Create tildes user
  16. become_user: postgres
  17. community.postgresql.postgresql_user:
  18. name: tildes
  19. role_attr_flags: "{{ postgresql_tildes_user_flags }}"
  20. # This is a bit of a hack to effectively enable looping over a block of tasks
  21. - name: Set up site database (and test database in dev version)
  22. include_tasks: database.yml
  23. loop: "{{ postgresql_tildes_databases }}"
  24. vars:
  25. extensions:
  26. - citext
  27. - ltree
  28. - intarray
  29. - pg_stat_statements
  30. - pg_trgm
  31. - plpython3u
  32. register: database_changes
  33. # Since handlers don't run until the end of the entire playbook, we need to run them
  34. # manually at this point in case postgresql or pgbouncer need to be reloaded
  35. - name: Trigger handlers to run manually for postgresql/pgbouncer updates
  36. meta: flush_handlers
  37. - name: Check if the database has already been initialized (will fail if not)
  38. become_user: postgres
  39. community.postgresql.postgresql_query:
  40. db: tildes
  41. query: select user_id from users;
  42. ignore_errors: true
  43. register: users_query
  44. - name: Initialize the database
  45. become_user: postgres
  46. command:
  47. cmd: "{{ bin_dir }}/python -c \"from scripts.initialize_db import initialize_db; initialize_db('{{ app_dir }}/{{ ini_file }}')\""
  48. chdir: "{{ app_dir }}"
  49. when: users_query is failed
  50. register: initialize_db
  51. - name: Insert dev data into database
  52. become_user: "{{ app_username }}"
  53. command:
  54. cmd: "{{ bin_dir }}/python -c \"from scripts.initialize_db import insert_dev_data; insert_dev_data('{{ app_dir }}/{{ ini_file }}')\""
  55. chdir: "{{ app_dir }}"
  56. when: tildes_database_insert_dev_data and initialize_db is changed