mirror of
https://github.com/2martens/cloud-configuration.git
synced 2026-10-17 08:37:56 +02:00
feat: Add roles for redis and postgresql on Uberspace
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
postgresql_version: 15
|
||||||
|
max_files_per_process: 64
|
||||||
|
max_worker_processes: 4
|
||||||
|
max_parallel_workers: 2
|
||||||
|
max_connections: 20
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: Set used postgresql version
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: uberspace tools version use postgresql {{ postgresql_version }}
|
||||||
|
changed_when: false
|
||||||
|
- name: Extend bash profile
|
||||||
|
ansible.builtin.import_tasks: profile.yaml
|
||||||
|
- name: Set up postgresql
|
||||||
|
ansible.builtin.import_tasks: setup.yaml
|
||||||
|
- name: Set up service
|
||||||
|
ansible.builtin.import_tasks: service.yaml
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
- name: Copy profile file to home dir
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: postgres_profile.j2
|
||||||
|
dest: ~/.postgres_profile
|
||||||
|
mode: 0644
|
||||||
|
register: postgres_profile
|
||||||
|
- name: Include postgres profile in bash_profile
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/.bash_profile
|
||||||
|
line: source ~/.postgres_profile
|
||||||
|
insertafter: EOF
|
||||||
|
when: postgres_profile.changed
|
||||||
|
- name: Source bash_profile
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: source ~/.bash_profile
|
||||||
|
when: postgres_profile.changed
|
||||||
|
- name: Copy environment var file to home dir
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: postgres_env.j2
|
||||||
|
dest: ~/.postgres_vars
|
||||||
|
mode: 0644
|
||||||
|
register: postgres_env
|
||||||
|
- name: include postgres vars in bashrc
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/.bashrc
|
||||||
|
line: source ~/.postgres_vars
|
||||||
|
insertafter: EOF
|
||||||
|
when: postgres_env.changed
|
||||||
|
- name: Source bashrc
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: source ~/.bashrc
|
||||||
|
when: postgres_env.changed
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
- name: Copy postgresql service
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: etc/services.d/postgresql.ini.j2
|
||||||
|
dest: /home/{{ ssh_user }}/etc/services.d/postgresql.ini
|
||||||
|
owner: "{{ ssh_user }}"
|
||||||
|
group: "{{ ssh_user }}"
|
||||||
|
mode: "644"
|
||||||
|
- name: Start postgresql
|
||||||
|
community.general.supervisorctl:
|
||||||
|
state: started
|
||||||
|
name: postgresql
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
---
|
||||||
|
- name: Create shared secret
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: openssl rand -hex 32
|
||||||
|
register: postgresql_secret
|
||||||
|
changed_when: false
|
||||||
|
- name: Create pgpass file
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: .pgpass.j2
|
||||||
|
dest: ~/.pgpass
|
||||||
|
owner: "{{ ssh_user }}"
|
||||||
|
group: "{{ ssh_user }}"
|
||||||
|
mode: "600"
|
||||||
|
- name: Create pgpass.temp file
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: .pgpass.temp.j2
|
||||||
|
dest: ~/.pgpass.temp
|
||||||
|
owner: "{{ ssh_user }}"
|
||||||
|
group: "{{ ssh_user }}"
|
||||||
|
mode: "600"
|
||||||
|
- name: Create database
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: initdb --pwfile ~/pgpass.temp --auth=scram-sha-256 -E UTF8 -D ~/opt/postgresql/data/
|
||||||
|
creates: ~/opt/postgresql/data
|
||||||
|
- name: Delete temporary password file
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: ~/.pgpass.temp
|
||||||
|
state: absent
|
||||||
|
- name: Update unix socket directories
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/opt/postgresql/data/postgresql.conf
|
||||||
|
regexp: '^#unix_socket_directories'
|
||||||
|
line: unix_socket_directories = '/home/{{ ssh_user }}/tmp' # comma-separated list of directories
|
||||||
|
- name: Configure max files per process
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/opt/postgresql/data/postgresql.conf
|
||||||
|
regexp: '^#?max_files_per_process'
|
||||||
|
line: max_files_per_process = {{ max_files_per_process }}
|
||||||
|
- name: Configure max worker processes
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/opt/postgresql/data/postgresql.conf
|
||||||
|
regexp: '^#?max_worker_processes'
|
||||||
|
line: max_worker_processes = {{ max_worker_processes }}
|
||||||
|
- name: Configure max parallel workers
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/opt/postgresql/data/postgresql.conf
|
||||||
|
regexp: '^#?max_parallel_workers'
|
||||||
|
line: max_parallel_workers = {{ max_parallel_workers }}
|
||||||
|
- name: Configure max connections
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/opt/postgresql/data/postgresql.conf
|
||||||
|
regexp: '^#?max_connections'
|
||||||
|
line: max_connections = {{ max_connections }}
|
||||||
|
- name: Configure log directory
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~/opt/postgresql/data/postgresql.conf
|
||||||
|
regexp: '^#?log_directory'
|
||||||
|
line: log_directory = /home/{{ ssh_user }}/logs
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[program:postgresql]
|
||||||
|
command=postgres -D %(ENV_HOME)s/opt/postgresql/data/
|
||||||
|
autostart=yes
|
||||||
|
autorestart=yes
|
||||||
|
startsecs=15
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
*:*:*:{{ ssh_user }}:{{ postgresql_secret.stdout }}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{{ postgresql_secret.stdout }}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export PGHOST=localhost
|
||||||
|
export PGPORT=5432
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Postgresql Environment
|
||||||
|
export PGPASSFILE=$HOME/.pgpass
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
- name: Create redis folder
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: directory
|
||||||
|
path: /home/{{ ssh_user }}/.redis
|
||||||
|
owner: "{{ ssh_user }}"
|
||||||
|
group: "{{ ssh_user }}"
|
||||||
|
mode: "755"
|
||||||
|
- name: Copy redis config
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: .redis/conf.j2
|
||||||
|
dest: /home/{{ ssh_user }}/.redis/conf
|
||||||
|
owner: "{{ ssh_user }}"
|
||||||
|
group: "{{ ssh_user }}"
|
||||||
|
mode: "644"
|
||||||
|
- name: Copy redis service
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: etc/services.d/redis.ini.j2
|
||||||
|
dest: /home/{{ ssh_user }}/etc/services.d/redis.ini
|
||||||
|
owner: "{{ ssh_user }}"
|
||||||
|
group: "{{ ssh_user }}"
|
||||||
|
mode: "644"
|
||||||
|
- name: Start redis
|
||||||
|
community.general.supervisorctl:
|
||||||
|
state: started
|
||||||
|
name: redis
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
unixsocket /home/{{ssh_user}}/.redis/sock
|
||||||
|
daemonize no
|
||||||
|
port 0
|
||||||
|
save ""
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[program:redis]
|
||||||
|
command=redis-server %(ENV_HOME)s/.redis/conf
|
||||||
|
directory=%(ENV_HOME)s/.redis
|
||||||
|
autostart=yes
|
||||||
|
autorestart=yes
|
||||||
|
startsecs=30
|
||||||
Reference in New Issue
Block a user