diff --git a/defaults/main.yml b/defaults/main.yml index b82887b8..5c2a33b3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,6 +8,10 @@ postgresql_locale: 'en_US.UTF-8' postgresql_admin_user: "postgres" postgresql_default_auth_method: "trust" +# The user/group that will run postgresql process or service +postgresql_service_user: "{{ postgresql_admin_user }}" +postgresql_service_group: "{{ postgresql_admin_user }}" + postgresql_cluster_name: "main" postgresql_cluster_reset: false diff --git a/tasks/configure.yml b/tasks/configure.yml index bcbdfcae..ea115de9 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -3,8 +3,8 @@ - name: PostgreSQL | Make sure the postgres data directory exists file: path: "{{postgresql_data_directory}}" - owner: "{{postgresql_admin_user}}" - group: "{{postgresql_admin_user}}" + owner: "{{ postgresql_service_user }}" + group: "{{ postgresql_service_group }}" state: directory mode: 0700 register: pgdata_dir_exist @@ -12,21 +12,21 @@ - name: PostgreSQL | Reset the cluster - drop the existing one shell: pg_dropcluster --stop {{postgresql_version}} {{postgresql_cluster_name}} sudo: yes - sudo_user: postgres + sudo_user: "{{ postgresql_service_user }}" when: postgresql_cluster_reset and pgdata_dir_exist.changed - name: PostgreSQL | Reset the cluster - create a new one (with specified encoding and locale) shell: pg_createcluster --start --locale {{postgresql_locale}} -e {{postgresql_encoding}} -d {{postgresql_data_directory}} {{postgresql_version}} {{postgresql_cluster_name}} sudo: yes - sudo_user: postgres + sudo_user: "{{ postgresql_service_user }}" when: postgresql_cluster_reset and pgdata_dir_exist.changed - name: PostgreSQL | Update configuration - pt. 1 (pg_hba.conf) template: src: pg_hba.conf.j2 dest: "{{postgresql_conf_directory}}/pg_hba.conf" - owner: "{{postgresql_admin_user}}" - group: "{{postgresql_admin_user}}" + owner: "{{ postgresql_service_user }}" + group: "{{ postgresql_service_group }}" mode: 0640 register: postgresql_configuration_pt1 @@ -34,17 +34,17 @@ template: src: postgresql.conf.j2 dest: "{{postgresql_conf_directory}}/postgresql.conf" - owner: "{{postgresql_admin_user}}" - group: "{{postgresql_admin_user}}" + owner: "{{ postgresql_service_user }}" + group: "{{ postgresql_service_group }}" mode: 0640 register: postgresql_configuration_pt2 - + - name: PostgreSQL | Create folder for additional configuration files file: name: "{{postgresql_conf_directory}}/conf.d" state: directory - owner: "{{postgresql_admin_user}}" - group: "{{postgresql_admin_user}}" + owner: "{{ postgresql_service_user }}" + group: "{{ postgresql_service_group }}" mode: 0755 - name: PostgreSQL | Restart PostgreSQL diff --git a/tasks/databases.yml b/tasks/databases.yml index 4a10df36..f22f2f3d 100644 --- a/tasks/databases.yml +++ b/tasks/databases.yml @@ -18,14 +18,14 @@ - name: PostgreSQL | Add hstore to the databases with the requirement sudo: yes - sudo_user: "{{postgresql_admin_user}}" + sudo_user: "{{ postgresql_service_user }}" shell: "psql {{item.name}} -c 'CREATE EXTENSION IF NOT EXISTS hstore;'" with_items: postgresql_databases when: item.hstore is defined and item.hstore - name: PostgreSQL | Add uuid-ossp to the database with the requirement sudo: yes - sudo_user: "{{postgresql_admin_user}}" + sudo_user: "{{ postgresql_service_user }}" shell: "psql {{item.name}} -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'" with_items: postgresql_databases when: item.uuid_ossp is defined and item.uuid_ossp