-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathpostgres.yaml
More file actions
59 lines (51 loc) · 1.84 KB
/
postgres.yaml
File metadata and controls
59 lines (51 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
- name: Install PostgreSQL 16
hosts: "{{ host }}"
vars:
ansible_ssh_user: "{{ admin_user }}"
tasks:
- name: Update apt and install required system packages
become: true
ansible.builtin.apt:
pkg:
- curl
- ca-certificates
state: latest
update_cache: true
- name: Ensure directory exists for postgres ca-certificates
become: true
ansible.builtin.file:
path: /usr/share/postgresql-common/pgdg
state: directory
mode: '0755'
- name: Download postgres ca-certificates if not already present
become: true
ansible.builtin.get_url:
url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
dest: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
mode: '0644'
force: no
- name: Add postgres apt repository
become: true
ansible.builtin.lineinfile:
path: /etc/apt/sources.list.d/pgdg.list
line: "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main"
state: present
create: true
- name: Install PostgreSQL 16
become: true
ansible.builtin.apt:
pkg:
- postgresql-16
state: latest
update_cache: true
- name: Create PostgreSQL credentials
shell:
cmd: |
sudo -u postgres psql -U postgres -c "CREATE USER {{ DB_USER }} WITH PASSWORD '{{ DB_PASS }}';"
sudo -u postgres psql -U postgres -c "CREATE DATABASE {{ DB_NAME }} OWNER {{ DB_USER }};"
vars:
DB_USER: "{{ lookup('ini', 'DB_USER', file=ini_file) }}"
DB_PASS: "{{ lookup('ini', 'DB_PASS', file=ini_file) }}"
DB_NAME: "{{ lookup('ini', 'DB_NAME', file=ini_file) }}"
ignore_errors: true
no_log: true