diff --git a/README.md b/README.md index 90001f3..c567e66 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,6 @@ Available variables are listed below, along with default values (see `defaults/m postgresql_enablerepo: "" -TODO. - - postgresql_data_dir: /var/lib/pgsql/data - TODO. postgresql_user: postgres @@ -37,7 +33,7 @@ TODO. encoding: 'UTF-8' # optional login_host: example.com # optional, defaults to 'localhost' login_password: supersecure # optional - login_user: admin # optional, defaults to 'postgres' + login_user: admin # optional, defaults to "{{ postgresql_user }}" port: 5432 # optional TODO. @@ -47,7 +43,7 @@ TODO. password: supersecure # optional login_host: example.com # optional, defaults to 'localhost' login_password: supersecure # optional - login_user: admin # optional, defaults to 'postgres' + login_user: admin # optional, defaults to "{{ postgresql_user }}" port: 1234 # optional, defaults to 5432 priv: table:priv1,priv2 # optional role_attr_flags: CREATEDB,NOSUPERUSER # optional diff --git a/defaults/main.yml b/defaults/main.yml index b4ec502..22de417 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,11 +2,11 @@ # RHEL/CentOS only. Set a repository to use for PostgreSQL installation. postgresql_enablerepo: "" -postgresql_data_dir: /var/lib/pgsql/data - postgresql_user: postgres postgresql_group: postgres +postgresql_unix_socket_dir: /var/run/postgresql + # Databases to ensure exist. postgresql_databases: [] # - name: example @@ -15,7 +15,7 @@ postgresql_databases: [] # encoding: 'UTF-8' # optional # login_host: example.com # optional, defaults to 'localhost' # login_password: supersecure # optional - # login_user: admin # optional, defaults to 'postgres' + # login_user: admin # optional, defaults to "{{ postgresql_user }}" # port: 5432 # optional # state: present # optional, defaults to 'present' @@ -25,7 +25,7 @@ postgresql_users: [] # password: supersecure # optional # login_host: example.com # optional, defaults to 'localhost' # login_password: supersecure # optional - # login_user: admin # optional, defaults to 'postgres' + # login_user: admin # optional, defaults to "{{ postgresql_user }}" # port: 1234 # optional, defaults to 5432 # priv: table:priv1,priv2 # optional # role_attr_flags: CREATEDB,NOSUPERUSER # optional diff --git a/handlers/main.yml b/handlers/main.yml index 614177a..523ad1b 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,3 +1,3 @@ --- - name: restart postgresql - service: "name={{ posgresql_daemon }} state=restarted sleep=5" + service: "name={{ postgresql_daemon }} state=restarted sleep=5" diff --git a/tasks/databases.yml b/tasks/databases.yml index 7d49784..fcde4e7 100644 --- a/tasks/databases.yml +++ b/tasks/databases.yml @@ -5,9 +5,16 @@ lc_collate: "{{ item.lc_collate | default('en_US.UTF-8') }}" lc_ctype: "{{ item.lc_ctype | default('en_US.UTF-8') }}" encoding: "{{ item.encoding | default('UTF-8') }}" + template: "{{ item.template | default('template0') }}" login_host: "{{ item.login_host | default('localhost') }}" login_password: "{{ item.login_password | default(omit) }}" - login_user: "{{ item.login_user | default('postgres') }}" - port: "{{ item.port | default('5432') }}" + login_user: "{{ item.login_user | default(postgresql_user) }}" + login_unix_socket: "{{ item.login_unix_socket | default(postgresql_unix_socket_dir) }}" + port: "{{ item.port | default(omit) }}" state: "{{ item.state | default('present') }}" with_items: "{{ postgresql_databases }}" + become: yes + become_user: "{{ postgresql_user }}" + # See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509 + vars: + ansible_ssh_pipelining: true diff --git a/tasks/initialize.yml b/tasks/initialize.yml index 807eb65..44ffd9b 100644 --- a/tasks/initialize.yml +++ b/tasks/initialize.yml @@ -4,6 +4,7 @@ src: postgres.sh.j2 dest: /etc/profile.d/postgres.sh mode: 0644 + notify: restart postgresql - name: Ensure PostgreSQL data directory exists. file: @@ -23,3 +24,6 @@ when: not pgdata_dir_version.stat.exists become: yes become_user: "{{ postgresql_user }}" + # See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509 + vars: + ansible_ssh_pipelining: true diff --git a/tasks/users.yml b/tasks/users.yml index 8edde57..fb0d3a8 100644 --- a/tasks/users.yml +++ b/tasks/users.yml @@ -3,12 +3,18 @@ postgresql_user: name: "{{ item.name }}" password: "{{ item.password | default(omit) }}" - login_host: "{{ item.login_host | default('localhost') }}" - login_password: "{{ item.login_password | default(omit) }}" - login_user: "{{ item.login_user | default('postgres') }}" - port: "{{ item.port | default('5432') }}" priv: "{{ item.priv | default(omit) }}" role_attr_flags: "{{ item.role_attr_flags | default(omit) }}" + login_host: "{{ item.login_host | default('localhost') }}" + login_password: "{{ item.login_password | default(omit) }}" + login_user: "{{ item.login_user | default(postgresql_user) }}" + login_unix_socket: "{{ item.login_unix_socket | default(postgresql_unix_socket_dir) }}" + port: "{{ item.port | default(omit) }}" state: "{{ item.state | default('present') }}" with_items: "{{ postgresql_users }}" - no_log: true + # no_log: true + become: yes + become_user: "{{ postgresql_user }}" + # See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509 + vars: + ansible_ssh_pipelining: true diff --git a/tasks/variables.yml b/tasks/variables.yml index e2b1b9e..08870f4 100644 --- a/tasks/variables.yml +++ b/tasks/variables.yml @@ -23,6 +23,11 @@ postgresql_version: "{{ __postgresql_version }}" when: postgresql_version is not defined +- name: Define postgresql_data_dir. + set_fact: + postgresql_data_dir: "{{ __postgresql_data_dir }}" + when: postgresql_data_dir is not defined + - name: Define postgresql_bin_path. set_fact: postgresql_bin_path: "{{ __postgresql_bin_path }}" diff --git a/vars/Debian-8.yml b/vars/Debian-8.yml index 1b88dec..9fd995a 100644 --- a/vars/Debian-8.yml +++ b/vars/Debian-8.yml @@ -1,5 +1,6 @@ --- __postgresql_version: "9.4" +__postgresql_data_dir: "/var/lib/postgresql/{{ __postgresql_version }}/main" __postgresql_bin_path: "/usr/lib/postgresql/{{ __postgresql_version }}/bin" __postgresql_daemon: postgresql __postgresql_packages: diff --git a/vars/RedHat.yml b/vars/RedHat.yml index fed2c4e..43ffeb6 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,5 +1,6 @@ --- __postgresql_version: "9.2" +__postgresql_data_dir: "/var/lib/pgsql/data" __postgresql_bin_path: "/usr/bin" __postgresql_daemon: postgresql __postgresql_packages: diff --git a/vars/Ubuntu-14.yml b/vars/Ubuntu-14.yml index 23f07cf..cd09ffa 100644 --- a/vars/Ubuntu-14.yml +++ b/vars/Ubuntu-14.yml @@ -1,5 +1,6 @@ --- __postgresql_version: "9.3" +__postgresql_data_dir: "/var/lib/postgresql/{{ __postgresql_version }}/main" __postgresql_bin_path: "/usr/lib/postgresql/{{ __postgresql_version }}/bin" __postgresql_daemon: postgresql __postgresql_packages: diff --git a/vars/Ubuntu-16.yml b/vars/Ubuntu-16.yml index 0d08efc..77fde1f 100644 --- a/vars/Ubuntu-16.yml +++ b/vars/Ubuntu-16.yml @@ -1,5 +1,6 @@ --- __postgresql_version: "9.5" +__postgresql_data_dir: "/var/lib/postgresql/{{ __postgresql_version }}/main" __postgresql_bin_path: "/usr/lib/postgresql/{{ __postgresql_version }}/bin" __postgresql_daemon: postgresql __postgresql_packages: