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.

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