Skip to content

Commit

Permalink
Merge branch 'slok-service-user'
Browse files Browse the repository at this point in the history
* slok-service-user:
  Added user service option in case you run postgres with a not default user
  • Loading branch information
pjan committed Jan 28, 2015
2 parents 840e93e + d0e8fc9 commit 78b1463
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@
- 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

- 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

- name: PostgreSQL | Update configuration - pt. 2 (postgresql.conf)
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
Expand Down
4 changes: 2 additions & 2 deletions tasks/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 78b1463

Please sign in to comment.