---
- name: Create PostgreSQL user for Redmine
  become_user: postgres
  postgresql_user:
    name: redmine
    password: redmine
  vars:
    ansible_ssh_pipelining: true

- name: Create PostgreSQL database for Redmine
  become_user: postgres
  postgresql_db:
    name: redmine
    encoding: UTF-8
    owner: redmine
  vars:
    ansible_ssh_pipelining: true

- name: Copy PostgreSQL dump file
  copy:
    src: benchmark-postgresql.dump.sql.xz
    dest: /tmp/benchmark-postgresql.dump.sql.xz

- name: Import PostgreSQL dump
  become_user: postgres
  shell: pxz -dc /tmp/benchmark-postgresql.dump.sql.xz | psql redmine
  vars:
    ansible_ssh_pipelining: true

- name: Create extension PGroonga
  become_user: postgres
  postgresql_ext:
    db: redmine
    name: pgroonga
  vars:
    ansible_ssh_pipelining: true

- name: Grant usage to redmine
  become_user: postgres
  postgresql_privs:
    database: redmine
    state: present
    privs: USAGE
    roles: redmine
    type: schema
    objs: pgroonga
    grant_option: yes
  vars:
    ansible_ssh_pipelining: true

---
- name: Create PostgreSQL user for Redmine
  become_user: postgres
  postgresql_user:
    name: redmine
    password: redmine
  vars:
    ansible_ssh_pipelining: true

- name: Create PostgreSQL database for Redmine
  become_user: postgres
  postgresql_db:
    name: redmine
    encoding: UTF-8
    owner: redmine
  vars:
    ansible_ssh_pipelining: true

- name: Copy PostgreSQL dump file
  copy:
    src: benchmark-postgresql.dump.sql.xz
    dest: /tmp/benchmark-postgresql.dump.sql.xz

- name: Import PostgreSQL dump
  become_user: postgres
  shell: pxz -dc /tmp/benchmark-postgresql.dump.sql.xz | psql redmine
  vars:
    ansible_ssh_pipelining: true

- name: Create extension PGroonga
  become_user: postgres
  postgresql_ext:
    db: redmine
    name: pgroonga
  vars:
    ansible_ssh_pipelining: true
  when: use_full_text_search

- name: Grant usage to redmine
  become_user: postgres
  postgresql_privs:
    database: redmine
    state: present
    privs: USAGE
    roles: redmine
    type: schema
    objs: pgroonga
    grant_option: yes
  vars:
    ansible_ssh_pipelining: true
  when: use_full_text_search

Stop creating PostgreSQL extension PGroonga
Stop creating PostgreSQL extension PGroonga

When full_text_search is not in use.
