1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 19:52:06 +00:00
iiab/roles/postgresql/tasks/main.yml

123 lines
3.9 KiB
YAML
Raw Normal View History

2020-01-24 01:57:14 +00:00
# TO DO:
# - validate input vars postgresql_install & postgresql_enabled
# - put the ~12 stanzas below into install.yml
# - when: postgresql_install is defined
- name: Install 'postgresql' package
2017-12-08 08:53:07 +00:00
package:
2018-10-28 16:23:25 +00:00
name: postgresql
2017-12-08 08:53:07 +00:00
state: present
2017-05-27 18:09:50 +00:00
2020-01-24 01:57:14 +00:00
- name: Install 'postgresql-client' package (debuntu)
2017-12-08 08:53:07 +00:00
package:
name: postgresql-client
2018-10-28 16:23:25 +00:00
state: present
when: is_debuntu | bool
2017-05-27 18:09:50 +00:00
2020-01-24 01:57:14 +00:00
- name: Install 'postgresql-server' package (OS's other than debuntu)
2017-12-08 08:53:07 +00:00
package:
name: postgresql-server
2018-10-28 16:23:25 +00:00
state: present
2017-05-27 23:10:45 +00:00
when: not is_debuntu
2017-05-27 18:09:50 +00:00
2018-10-31 07:22:27 +00:00
- name: Install /etc/systemd/system/postgresql-iiab.service from template
2017-12-08 08:53:07 +00:00
template:
src: postgresql-iiab.service
dest: /etc/systemd/system/postgresql-iiab.service
2020-01-24 01:57:14 +00:00
# owner: root
# group: root
# mode: '0644'
2017-05-27 18:09:50 +00:00
2018-10-31 07:22:27 +00:00
- name: Create PostgreSQL data dir /library/pgsql-iiab, owned by postgres:postgres
2017-12-08 08:53:07 +00:00
file:
path: /library/pgsql-iiab
owner: postgres
group: postgres
mode: '0700'
2017-12-08 08:53:07 +00:00
state: directory
2017-05-27 18:09:50 +00:00
2018-10-31 07:22:27 +00:00
- name: Make sure locale {{ postgresql_locale }} is enabled (debuntu) # en_US.UTF-8
2017-12-08 08:53:07 +00:00
lineinfile:
dest: /etc/locale.gen
line: "{{ postgresql_locale }} UTF-8"
when: is_debuntu | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:22:27 +00:00
- name: Generate locales (debuntu)
2017-05-27 18:09:50 +00:00
command: /usr/sbin/locale-gen
when: is_debuntu | bool
2017-05-27 18:09:50 +00:00
2018-10-31 07:22:27 +00:00
- name: Initialize the PostgreSQL db, creating /library/pgsql-iiab/pg_hba.conf (debuntu)
2018-10-29 04:28:17 +00:00
#command: su - postgres -c "/usr/lib/postgresql/{{ postgresql_version }}/bin/initdb -E 'UTF-8' --locale={{ postgresql_locale }} -D /library/pgsql-iiab"
command: /usr/lib/postgresql/{{ postgresql_version }}/bin/initdb -E 'UTF-8' --locale={{ postgresql_locale }} -D /library/pgsql-iiab
2017-12-08 08:53:07 +00:00
args:
creates: /library/pgsql-iiab/pg_hba.conf
2018-10-29 04:28:17 +00:00
become: yes
become_user: postgres
when: is_debuntu | bool
2017-05-27 23:10:45 +00:00
2018-10-31 07:22:27 +00:00
- name: Initialize the PostgreSQL db, creating /library/pgsql-iiab/pg_hba.conf (OS's other than debuntu)
2018-10-29 04:28:17 +00:00
#command: su - postgres -c "/usr/bin/initdb -E 'UTF-8' --lc-collate={{ postgresql_locale }} --lc-ctype={{ postgresql_locale }} -D /library/pgsql-iiab"
command: /usr/bin/initdb -E 'UTF-8' --lc-collate={{ postgresql_locale }} --lc-ctype={{ postgresql_locale }} -D /library/pgsql-iiab
2017-12-08 08:53:07 +00:00
args:
creates: /library/pgsql-iiab/pg_hba.conf
2018-10-29 04:28:17 +00:00
become: yes
become_user: postgres
2017-05-27 23:10:45 +00:00
when: not is_debuntu
2017-05-27 18:09:50 +00:00
2018-10-31 07:22:27 +00:00
- name: Install /library/pgsql-iiab/postgresql.conf owned by postgres:postgres, from template
2017-12-08 08:53:07 +00:00
template:
backup: yes
src: postgresql.conf.j2
dest: /library/pgsql-iiab/postgresql.conf
owner: postgres
group: postgres
mode: '0640'
2017-05-27 18:09:50 +00:00
2020-01-24 01:57:14 +00:00
# Likely No Longer Nec! Given stanza below does the same...
#- name: 'Stop postgresql service: /etc/init.d/postgresql stop (debuntu)'
# command: "/etc/init.d/postgresql stop"
# ignore_errors: True
# when: postgresql_install and is_debuntu
2020-01-24 01:57:14 +00:00
- name: Disable & Stop stock 'postgresql' systemd service
2018-10-31 07:22:27 +00:00
systemd:
2017-12-08 08:53:07 +00:00
name: postgresql
state: stopped
enabled: no
2017-05-27 18:09:50 +00:00
2020-01-24 01:57:14 +00:00
- name: "Add 'postgresql_installed: True' to {{ iiab_state_file }}"
lineinfile:
dest: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp: '^postgresql_installed'
line: 'postgresql_installed: True'
- name: Enable & Start 'postgresql-iiab' systemd service, if 'postgresql_enabled'
2018-10-31 07:22:27 +00:00
systemd:
2017-12-08 08:53:07 +00:00
name: postgresql-iiab
state: started
enabled: yes
when: postgresql_enabled | bool
2017-05-27 18:09:50 +00:00
2020-01-24 01:57:14 +00:00
- name: Disable 'postgresql-iiab' systemd service, if not 'postgresql_enabled'
2018-10-31 07:22:27 +00:00
systemd:
2017-12-08 08:53:07 +00:00
name: postgresql-iiab
state: stopped
enabled: no
when: not postgresql_enabled
2018-10-31 07:22:27 +00:00
- name: Add 'postgresql' variable values to {{ iiab_ini_file }}
2017-12-08 08:53:07 +00:00
ini_file:
2018-10-31 07:22:27 +00:00
path: "{{ iiab_ini_file }}"
2017-12-08 08:53:07 +00:00
section: postgresql
option: "{{ item.option }}"
value: "{{ item.value | string }}"
2017-05-27 18:09:50 +00:00
with_items:
- option: name
2017-12-08 10:38:26 +00:00
value: PostgreSQL
2017-05-27 18:09:50 +00:00
- option: description
value: '"PostgreSQL is a powerful, open source object-relational database system."'
- option: installed
value: "{{ postgresql_install }}"
- option: enabled
value: "{{ postgresql_enabled }}"