diff --git a/tasks/initialize.yml b/tasks/initialize.yml index 932b193..e7d9875 100644 --- a/tasks/initialize.yml +++ b/tasks/initialize.yml @@ -21,7 +21,8 @@ - name: Ensure PostgreSQL database is initialized. command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }} --locale=C.UTF-8 --encoding=UTF8 --data-checksums" - when: not pgdata_dir_version.stat.exists + when: not pgdata_dir_version.stat.exists and (postgres_consul_tag is not defined or postgres_consul_tag == "active") + become: true become_user: "{{ postgresql_user }}" # See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509 diff --git a/tasks/main.yml b/tasks/main.yml index 3c5fa3e..e1cf7b5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,17 +14,19 @@ - include_tasks: initialize.yml - include_tasks: configure.yml - + when: postgres_consul_tag is not defined or postgres_consul_tag == "active" - name: Ensure PostgreSQL is started and enabled on boot. service: name: "{{ postgresql_daemon }}" state: "{{ postgresql_service_state }}" enabled: "{{ postgresql_service_enabled }}" + when: postgres_consul_tag is not defined or postgres_consul_tag == "active" # Configure PostgreSQL. - import_tasks: users.yml + when: postgres_consul_tag is not defined or postgres_consul_tag == "active" - import_tasks: databases.yml - + when: postgres_consul_tag is not defined or postgres_consul_tag == "active" - name: Import Consul service task ansible.builtin.import_tasks: consul.yml when: postgres_consul_service