ansible-role-mastodon/tasks/bare/postgresql_database.yml

74 lines
2.3 KiB
YAML

#Debian PostgreSQL installation automatically calls initdb i.e. it initializes the cluster with default encoding and locale.
#https://wiki.debian.org/PostgreSql
#RHEL requires manual initialisation
- name: "Find out if PostgreSQL is initialized"
stat:
path: "/var/lib/pgsql/data/pg_hba.conf"
register: postgres_data
when:
- ansible_os_family == "RedHat"
- name: "Initialize PostgreSQL"
shell: "postgresql-setup initdb"
when:
- ansible_os_family == "RedHat"
- not postgres_data.stat.exists
- name: "Start and enable services"
become: true
#Workaround for "Interactive authentication required" issue
become_user: root
service: "name={{ item }} state=started enabled=yes"
with_items:
- postgresql
- name: Create remote database {{ mastodon_db }}
postgresql_db:
name: "{{ mastodon_db }}"
login_host: "{{ mastodon_db_login_host }}"
login_password: "{{ mastodon_db_login_password }}"
login_user: "{{ mastodon_db_login_user }}"
port: "{{ mastodon_db_port }}"
register: create_remote_db
when:
- mastodon_db_login_user is defined
- mastodon_db_login_host is defined
- mastodon_db_login_password is defined
- mastodon_db_port is defined
- name: Create remote database user {{ mastodon_db_user }}
postgresql_user:
db: "{{ mastodon_db }}"
name: "{{ mastodon_db_user }}"
password: "{{ mastodon_db_password }}"
login_host: "{{ mastodon_db_login_host }}"
login_password: "{{ mastodon_db_login_password }}"
login_user: "{{ mastodon_db_login_user }}"
port: "{{ mastodon_db_port }}"
role_attr_flags: CREATEDB
register: create_remote_db_user
when:
- mastodon_db_login_user is defined
- mastodon_db_login_host is defined
- mastodon_db_login_password is defined
- mastodon_db_port is defined
- name: Create database {{ mastodon_db }}
become: true
postgresql_db:
name: "{{ mastodon_db }}"
login_unix_socket: "{{ mastodon_db_login_unix_socket }}"
register: create_local_db
when: create_remote_db is skipped
- name: Create database user {{ mastodon_db_user }}
become: true
postgresql_user:
db: "{{ mastodon_db }}"
name: "{{ mastodon_db_user }}"
password: "{{ mastodon_db_password }}"
encrypted: true
login_unix_socket: "{{ mastodon_db_login_unix_socket }}"
role_attr_flags: CREATEDB
when: create_remote_db_user is skipped