Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ SHELL := /bin/bash
INVENTORY ?= staging
VERSION ?= latest

ANSIBLE_CONFIG := ansible/ansible.cfg
export ANSIBLE_CONFIG

ANSIBLE := ansible-playbook -i ansible/inventory/$(INVENTORY).yml

# =============================================================================
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,56 @@ ansible/
observability/ # Prometheus rules, Grafana dashboards
```

## New server setup

Before running Ansible, prepare the server manually:

1. Generate an SSH key pair (if you don't have one):
```bash
ssh-keygen -t ed25519 -C "guitar0-deploy"
```

2. Add your public key to the server via the hosting control panel, or copy it as root:
```bash
ssh root@<server-ip>
mkdir -p /home/deploy/.ssh
echo "<your public key>" >> /home/deploy/.ssh/authorized_keys
```

3. Create the `deploy` user with passwordless sudo:
```bash
adduser deploy
echo "deploy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/deploy
mkdir -p /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh && chmod 600 /home/deploy/.ssh/authorized_keys
```

4. Update `ansible/inventory/production.yml` with the new server IP/hostname.

5. Create the vault password file:
```bash
echo "<vault-password>" > ansible/.vault_pass
chmod 600 ansible/.vault_pass
```

6. Remove the old host key and trust the new server:
```bash
ssh-keygen -R <server-hostname>
ssh-keyscan -H <server-hostname> >> ~/.ssh/known_hosts
```

7. Verify connectivity:
```bash
make ping INVENTORY=production SSH_PRIVATE_KEY_FILE=~/.ssh/<your-key>
```

8. Run one-time setup:
```bash
make setup INVENTORY=production SSH_PRIVATE_KEY_FILE=~/.ssh/<your-key>
```

## Usage

```bash
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/backend/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
services:
- db
state: present
pull: never
pull: missing

- name: Run migrations
ansible.builtin.command:
Expand Down
11 changes: 10 additions & 1 deletion ansible/roles/backend/tasks/directories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
loop:
- "{{ backend_app_dir }}"
- "{{ backend_shared_dir }}"
- "{{ backend_backup_dir }}"

- name: Create backend directories writable by container appuser (uid=1001)
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "1001"
group: "1001"
mode: "0755"
loop:
- "{{ backend_shared_dir }}/staticfiles"
- "{{ backend_shared_dir }}/media"
- "{{ backend_backup_dir }}"
- "{{ backend_log_dir }}"
3 changes: 3 additions & 0 deletions ansible/roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ firewall_allowed_ports:
fail2ban_bantime: 3600
fail2ban_findtime: 600
fail2ban_maxretry: 3

# Log directory
log_dir: /var/log
7 changes: 7 additions & 0 deletions ansible/roles/common/templates/jail.local.j2
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ logpath = {{ log_dir }}/nginx/error.log
maxretry = 10
findtime = 60
bantime = 600

[recidive]
enabled = true
logpath = /var/log/fail2ban.log
bantime = 1w
findtime = 1d
maxretry = 5
Loading