Skip to content

Commit 39f232b

Browse files
committed
feat: integration of nix with packer/ansible stage2 steps
1 parent 195c170 commit 39f232b

12 files changed

+213
-145
lines changed

ansible/playbook.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
- set_fact:
2828
parallel_jobs: 16
2929

30-
- name: Install Postgres from source
30+
- name: Prepare machine for Postgres installation
3131
import_tasks: tasks/setup-postgres.yml
3232

3333
- name: Install PgBouncer
@@ -76,11 +76,6 @@
7676
src: files/apt_periodic
7777
dest: /etc/apt/apt.conf.d/10periodic
7878

79-
- name: First boot optimizations
80-
import_tasks: tasks/internal/optimizations.yml
81-
tags:
82-
- install-supabase-internal
83-
8479
- name: Finalize AMI
8580
import_tasks: tasks/finalize-ami.yml
8681
tags:
@@ -110,9 +105,3 @@
110105

111106
- name: Clean out build dependencies
112107
import_tasks: tasks/clean-build-dependencies.yml
113-
114-
# - name: Collect Postgres binaries
115-
# import_tasks: tasks/internal/collect-pg-binaries.yml
116-
# tags:
117-
# - collect-binaries
118-
#TODO bring into 2nd phase

ansible/tasks/finalize-ami.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,3 @@
7070
sed -i -e 's;daily;*:0/5;' /etc/systemd/system/logrotate.timer
7171
systemctl reenable logrotate.timer
7272
become: yes
73-
74-
# - name: import pgsodium_getkey script
75-
# template:
76-
# src: files/pgsodium_getkey_readonly.sh.j2
77-
# dest: "{{ pg_bindir }}/pgsodium_getkey.sh"
78-
# owner: postgres
79-
# group: postgres
80-
# mode: 0700
81-
# TODO bring into 2nd phase

ansible/tasks/internal/optimizations.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# - name: ensure services are stopped
2+
# community.general.snap:
3+
# name: amazon-ssm-agent
4+
# state: absent
5+
# TODO taking this out as machine at this stage reports
6+
# that aws-ssm-agent is not installed at all
7+
8+
- name: ensure services are stopped and disabled for first boot
9+
systemd:
10+
enabled: no
11+
name: '{{ item }}'
12+
state: stopped
13+
with_items:
14+
#- snapd
15+
- postgresql
16+
- pgbouncer
17+
- fail2ban
18+
- motd-news
19+
- vector
20+
21+
- name: Remove snapd
22+
apt:
23+
state: absent
24+
pkg:
25+
- snapd
26+
27+
# - name: ensure services are stopped and disabled for first boot
28+
# systemd:
29+
# enabled: no
30+
# name: '{{ item }}'
31+
# state: stopped
32+
# masked: yes
33+
# with_items:
34+
# - lvm2-monitor
35+
# machine at this stage reports this service is stopped and disabled
36+
37+
38+
- name: disable man-db
39+
become: yes
40+
file:
41+
state: absent
42+
path: "/etc/cron.daily/{{ item }}"
43+
with_items:
44+
- man-db
45+
- popularity-contest
46+
- ubuntu-advantage-tools

ansible/tasks/stage2/playbook.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
- hosts: localhost
22
become: yes
33

4+
vars:
5+
sql_files:
6+
- "/tmp/ansible-playbook/files/pgbouncer_config/pgbouncer_auth_schema.sql"
7+
- "/tmp/ansible-playbook/files/stat_extension.sql"
8+
49

510
tasks:
611
- set_fact:
@@ -13,3 +18,11 @@
1318

1419
- name: Install Postgres from nix binary cache
1520
import_tasks: stage2-setup-postgres.yml
21+
22+
- name: First boot optimizations
23+
import_tasks: optimizations.yml
24+
25+
- name: Run unit tests
26+
import_tasks: test-image.yml
27+
tags:
28+
- unit-tests

ansible/tasks/setup-docker.yml renamed to ansible/tasks/stage2/setup-extensions.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
- name: Copy extension packages
2-
copy:
3-
src: files/extensions/
4-
dest: /tmp/extensions/
1+
# - name: Copy extension packages
2+
# copy:
3+
# src: files/extensions/
4+
# dest: /tmp/extensions/
5+
6+
# # Builtin apt module does not support wildcard for deb paths
7+
# - name: Install extensions
8+
# shell: |
9+
# set -e
10+
# apt-get update
11+
# apt-get install -y --no-install-recommends /tmp/extensions/*.deb
12+
# TODO remove
513

6-
# Builtin apt module does not support wildcard for deb paths
7-
- name: Install extensions
8-
shell: |
9-
set -e
10-
apt-get update
11-
apt-get install -y --no-install-recommends /tmp/extensions/*.deb
1214

1315
- name: pg_cron - set cron.database_name
1416
become: yes
@@ -17,11 +19,8 @@
1719
state: present
1820
line: cron.database_name = 'postgres'
1921

20-
- name: pgsodium - determine postgres bin directory
21-
shell: pg_config --bindir
22-
register: pg_bindir_output
2322
- set_fact:
24-
pg_bindir: "{{ pg_bindir_output.stdout }}"
23+
pg_bindir: "/usr/lib/postgresql/bin"
2524

2625
- name: pgsodium - set pgsodium.getkey_script
2726
become: yes
@@ -48,15 +47,15 @@
4847

4948
- name: supautils - write custom supautils.conf
5049
template:
51-
src: "files/postgresql_config/supautils.conf.j2"
50+
src: "/tmp/ansible-playbook/files/postgresql_config/supautils.conf.j2"
5251
dest: /etc/postgresql-custom/supautils.conf
5352
mode: 0664
5453
owner: postgres
5554
group: postgres
5655

5756
- name: supautils - copy extension custom scripts
5857
copy:
59-
src: files/postgresql_extension_custom_scripts/
58+
src: /tmp/ansible-playbook/files/postgresql_extension_custom_scripts/
6059
dest: /etc/postgresql-custom/extension-custom-scripts
6160
become: yes
6261

@@ -76,7 +75,8 @@
7675
regexp: "#include = '/etc/postgresql-custom/supautils.conf'"
7776
replace: "include = '/etc/postgresql-custom/supautils.conf'"
7877

79-
- name: Cleanup - extension packages
80-
file:
81-
path: /tmp/extensions
82-
state: absent
78+
# - name: Cleanup - extension packages
79+
# file:
80+
# path: /tmp/extensions
81+
# state: absent
82+
# TODO remove
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- name: Run migrate.sh script
2+
shell: . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && ./migrate.sh
3+
register: retval
4+
args:
5+
chdir: /tmp/migrations/db
6+
become: yes
7+
become_user: postgres
8+
failed_when: retval.rc != 0
9+
10+
- name: Create /root/MIGRATION-AMI file
11+
file:
12+
path: "/root/MIGRATION-AMI"
13+
state: touch

0 commit comments

Comments
 (0)