|
1 | 1 | # Downloading dependencies
|
2 |
| -- name: Postgres dependencies |
| 2 | +- name: GPG dependencies |
3 | 3 | apt:
|
4 |
| - pkg: |
5 |
| - - build-essential |
6 |
| - - pkg-config |
7 |
| - - libreadline-dev |
8 |
| - - zlib1g-dev |
9 |
| - - flex |
10 |
| - - bison |
11 |
| - - libxml2-dev |
12 |
| - - libxslt-dev |
13 |
| - - libssl-dev |
14 |
| - - libsystemd-dev |
15 |
| - - libxml2-utils |
16 |
| - - uuid-dev |
17 |
| - - xsltproc |
18 |
| - - ssl-cert |
19 |
| - - liblz4-dev |
20 |
| - - libicu-dev |
21 |
| - |
22 |
| -- name: Download LLVM & Clang |
23 |
| - apt: |
24 |
| - pkg: |
25 |
| - - llvm-11-dev |
26 |
| - - clang-11 |
27 |
| - when: ansible_distribution_version != "18.04" |
| 4 | + name: gnupg |
28 | 5 |
|
29 |
| -- name: Download LLVM & Clang - Ubuntu 18.04 |
30 |
| - apt: |
31 |
| - pkg: |
32 |
| - - llvm-12-dev |
33 |
| - - clang-12 |
34 |
| - when: ansible_distribution_version == "18.04" |
| 6 | +- name: Add Postgres GPG key |
| 7 | + apt_key: |
| 8 | + keyserver: keyserver.ubuntu.com |
| 9 | + id: B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 |
35 | 10 |
|
36 |
| -- name: Download GCC 10 |
| 11 | +- name: Add Postgres PPA |
| 12 | + apt_repository: |
| 13 | + repo: "deb https://apt-archive.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg-archive main" |
| 14 | + state: present |
| 15 | + |
| 16 | +- name: Postgres - install commons |
37 | 17 | apt:
|
38 |
| - pkg: |
39 |
| - - gcc-10 |
40 |
| - - g++-10 |
| 18 | + name: postgresql-common |
| 19 | + state: latest |
| 20 | + update_cache: yes |
41 | 21 |
|
42 |
| -- name: Switch to GCC 10 |
| 22 | +- name: Do not create main cluster |
43 | 23 | shell:
|
44 |
| - cmd: update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10 |
| 24 | + cmd: sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf |
45 | 25 |
|
46 |
| -# Setup permissions |
47 |
| -- name: Update permissions for /var/tmp directory |
48 |
| - file: |
49 |
| - path: /var/tmp/ |
50 |
| - owner: root |
51 |
| - group: root |
52 |
| - mode: '1777' |
53 |
| - become: yes |
| 26 | +- name: Postgres - install server |
| 27 | + apt: |
| 28 | + name: postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1 |
54 | 29 |
|
55 |
| -# Building Postgres from source |
56 |
| -- name: Postgres - download latest release |
57 |
| - get_url: |
58 |
| - url: https://ftp.postgresql.org/pub/source/v{{ postgresql_release }}/postgresql-{{ postgresql_release }}.tar.gz |
59 |
| - dest: /tmp |
60 |
| - checksum: "{{ postgresql_release_checksum }}" |
61 |
| - timeout: 60 |
62 |
| - |
63 |
| -- name: Postgres - unpack archive |
64 |
| - unarchive: |
65 |
| - remote_src: yes |
66 |
| - src: /tmp/postgresql-{{ postgresql_release }}.tar.gz |
67 |
| - dest: /tmp |
68 |
| - |
69 |
| -- name: Setting CFLAGS (arm) |
70 |
| - set_fact: |
71 |
| - cflags: "-moutline-atomics -mtune=native -march=native -mcpu=native -fsigned-char -O2" |
72 |
| - when: platform == "arm64" and ansible_distribution_version != "18.04" |
73 |
| - |
74 |
| -- name: Setting CFLAGS (arm) - Ubuntu 18.04 |
75 |
| - set_fact: |
76 |
| - cflags: "-moutline-atomics -fsigned-char -O2" |
77 |
| - when: platform == "arm64" and ansible_distribution_version == "18.04" |
78 |
| - |
79 |
| -- name: Setting CFLAGS (x86) |
80 |
| - set_fact: |
81 |
| - cflags: "-fsigned-char" |
82 |
| - when: platform == "amd64" |
83 |
| - |
84 |
| -- name: Setting LLVM_CONFIG |
85 |
| - set_fact: |
86 |
| - llvm_config: "/usr/bin/llvm-config-11" |
87 |
| - clang: "/usr/bin/clang-11" |
88 |
| - when: ansible_distribution_version != "18.04" |
89 |
| - |
90 |
| -- name: Setting LLVM_CONFIG - Ubuntu 18.04 |
91 |
| - set_fact: |
92 |
| - llvm_config: "/usr/bin/llvm-config-12" |
93 |
| - clang: "/usr/bin/clang-12" |
94 |
| - when: ansible_distribution_version == "18.04" |
95 |
| - |
96 |
| -- name: Postgres - configure |
| 30 | +- name: Create symlink to /usr/lib/postgresql/bin |
97 | 31 | shell:
|
98 |
| - cmd: CFLAGS='{{ cflags }}' LLVM_CONFIG='{{ llvm_config }}' CLANG='{{ clang }}' ./configure --with-llvm --with-openssl --with-systemd --with-uuid=e2fs --with-libxml --with-icu --with-lz4 --exec-prefix=/usr/lib/postgresql --datarootdir=/var/lib/postgresql |
99 |
| - chdir: /tmp/postgresql-{{ postgresql_release }} |
100 |
| - |
101 |
| -- name: Postgres - build |
102 |
| - community.general.make: |
103 |
| - target: world-bin |
104 |
| - chdir: /tmp/postgresql-{{ postgresql_release }} |
105 |
| - jobs: "{{ parallel_jobs | default(omit) }}" |
106 |
| - |
107 |
| -- name: Postgres - install |
108 |
| - make: |
109 |
| - target: install-world-bin |
110 |
| - chdir: /tmp/postgresql-{{ postgresql_release }} |
111 |
| - |
112 |
| -- name: Create postgres group |
113 |
| - group: |
114 |
| - name: postgres |
115 |
| - state: present |
116 |
| - |
117 |
| -# Create postgres user |
118 |
| -- name: Create postgres user |
119 |
| - user: |
120 |
| - name: postgres |
121 |
| - shell: /bin/false |
122 |
| - comment: Postgres user |
123 |
| - group: postgres |
124 |
| - groups: postgres,ssl-cert |
| 32 | + cmd: ln -s /usr/lib/postgresql/{{ postgresql_major }}/bin /usr/lib/postgresql/bin |
125 | 33 |
|
126 | 34 | - name: Create relevant directories
|
127 | 35 | file:
|
|
131 | 39 | owner: postgres
|
132 | 40 | group: postgres
|
133 | 41 | with_items:
|
134 |
| - - '/etc/postgresql' |
135 |
| - - '/etc/postgresql-custom' |
| 42 | + - '/home/postgres' |
136 | 43 | - '/var/log/postgresql'
|
137 | 44 | - '/var/lib/postgresql'
|
138 | 45 |
|
|
181 | 88 | dest: /etc/postgresql/pg_ident.conf
|
182 | 89 | group: postgres
|
183 | 90 |
|
184 |
| -- name: Find all files in /usr/lib/postgresql/bin |
185 |
| - find: |
186 |
| - paths: /usr/lib/postgresql/bin |
187 |
| - register: postgresql_bin |
188 |
| - |
189 |
| -- name: Create symbolic links for Postgres binaries to /usr/bin/ |
190 |
| - become: yes |
191 |
| - file: |
192 |
| - src: "{{ item.path }}" |
193 |
| - path: "/usr/bin/{{ item.path | basename }}" |
194 |
| - state: link |
195 |
| - force: yes |
196 |
| - with_items: "{{ postgresql_bin.files }}" |
| 91 | +# Install extensions before init |
| 92 | +- name: Install Postgres extensions |
| 93 | + import_tasks: tasks/setup-docker.yml |
197 | 94 |
|
198 | 95 | # init DB
|
199 | 96 | - name: Create directory on data volume
|
|
0 commit comments