--- a/postgresql/tasks/main.yaml Sun Jan 21 15:58:58 2024 -0600
+++ b/postgresql/tasks/main.yaml Sun Feb 04 20:27:19 2024 -0600
@@ -22,6 +22,17 @@
group: "postgres"
notify: restart postgres
+- name: check if postgresql data dir is new
+ become: yes
+ find: path='{{postgresql_data_dir}}'
+ register: filesFound
+
+- name: initialize pg data dir
+ become: yes
+ become_user: "postgres"
+ command: "{{postgresql_initidb_path}} -D {{postgresql_data_dir}}"
+ when: filesFound == 0
+
- name: ensure postgresql is started
become: yes
systemd: name="postgresql" enabled="yes" state="started"