9 Commits

Author SHA1 Message Date
1747125b67 roles/blog: fix updateBlog 2023-01-17 17:52:47 -06:00
41ef83bb4e roles/blog: run updateBlog; now idempotent! 2023-01-17 17:41:25 -06:00
4359544b6a blog: updateBlog now checks for changes before building 2023-01-17 17:32:47 -06:00
ca6fdaeff3 blog: maintain two separate builds of the site; one for tor, one for https 2023-01-16 17:17:07 -06:00
1028023b8b roles/nginx: made idempotent 2023-01-15 21:54:03 -06:00
5e2c4850e1 minor README changes 2023-01-14 17:36:51 -06:00
a971e7d065 github: disabled deploy workflow 2023-01-14 17:31:46 -06:00
abaa4c9639 switched to roles
- all tasks/* have been moved to their own roles in roles/*
- each file && template is now oragnized per-role
- annotated each task which still isn't idempotent !TODO!
2023-01-14 17:26:17 -06:00
d435ab80ac fix: wrong paths in imdead.sh (oops) 2022-10-04 13:13:46 -05:00
32 changed files with 154 additions and 118 deletions

View File

@@ -1,27 +1,27 @@
name: Run Playbook # name: Run Playbook
on: # on:
push: # push:
tags: # tags:
- "v*.*.*" # - "v*.*.*"
jobs: # jobs:
deploy: # deploy:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
steps: # steps:
- name: Set up Git repository # - name: Set up Git repository
uses: actions/checkout@v3 # uses: actions/checkout@v3
with: # with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} # ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
submodules: recursive # submodules: recursive
- name: Run Ansible-Playbook # - name: Run Ansible-Playbook
uses: dawidd6/action-ansible-playbook@v2 # uses: dawidd6/action-ansible-playbook@v2
with: # with:
playbook: run.yml # playbook: run.yml
key: ${{ secrets.SSH_PRIVATE_KEY }} # key: ${{ secrets.SSH_PRIVATE_KEY }}
inventory: | # inventory: |
[hosts] # [hosts]
openpunk-vps ansible_host=96.30.199.68 ansible_user=root ansible_connection=ssh # openpunk-vps ansible_host=96.30.199.68 ansible_user=root ansible_connection=ssh
vault_password: ${{ secrets.VAULT_PASSWORD }} # vault_password: ${{ secrets.VAULT_PASSWORD }}
options: | # options: |
--extra-vars domain=openpunk.com # --extra-vars domain=openpunk.com

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"yaml.schemas": {
"https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/tasks": "file:///home/cpunch/projects/openpunk-ansible/roles/nginx/tasks/main.yml"
}
}

View File

@@ -1,12 +1,11 @@
# OpenPunk's Ansible playbook # OpenPunk's Ansible playbook
<p align="center">
<a href="https://github.com/CPunch/openpunk-ansible/actions/workflows/deploy.yaml"><img src="https://github.com/CPunch/openpunk-ansible/actions/workflows/deploy.yaml/badge.svg?branch=main" alt="Workflow"></a>
</p>
This is my failsafe (and also my helpful migration tool) for restoring the OpenPunk server. This handles setting everything back up, including: This is my failsafe (and also my helpful migration tool) for restoring the OpenPunk server. This handles setting everything back up, including:
- gitea - gitea
- sadly, no db migration is supported right now. maybe a future todo?
- blog - blog
- cron job for grabbing the `HEAD` of https://github.com/CPunch/openpunk && building the hugo site
- tor mirror - tor mirror
- nginx (for the above mentioned) - nginx (for the above mentioned)
- my shell theme (zsh + powerlevel10k) - my shell theme (zsh + powerlevel10k)
@@ -14,12 +13,12 @@ This is my failsafe (and also my helpful migration tool) for restoring the OpenP
This playbook assumes the target VPS is running the latest debian stable release. This playbook assumes the target VPS is running the latest debian stable release.
## Automatic deployment
On new release tags the playbook is automatically ran on the production openpunk vps. For more info checkout the `.github/workflows/deploy.yaml` workflow
## Notes to my future self ## Notes to my future self
The deadswitch has the deadtrigger setup every run, so you have a 14-day timer to add a one-liner to your crontab to keep that deadtrigger set. The deadswitch has the deadtrigger setup every run, so you have a 14-day timer to add a one-liner to your crontab to keep that deadtrigger set.
Some DNS records also need to be set:
- an A record with a `git.*` subdomain
## Usage ## Usage
```sh ```sh
ansible-playbook -i hosts --ask-vault-pass run.yml ansible-playbook -i hosts --ask-vault-pass run.yml

View File

@@ -1,2 +1,3 @@
--- ---
contact_email: openpunk@proton.me contact_email: openpunk@proton.me
onionDomain: http://opnpnk6eutjiqy4ndpyvwxd5pncj2g2cmz6fkocr5uh3omnn4utvspad.onion

View File

@@ -4,17 +4,18 @@
repo: "https://github.com/CPunch/openpunk.git" repo: "https://github.com/CPunch/openpunk.git"
dest: "/var/www/{{ domain }}" dest: "/var/www/{{ domain }}"
- name: Build blog
command:
cmd: hugo
chdir: "/var/www/{{ domain }}"
- name: Install updateBlog script - name: Install updateBlog script
template: template:
src: templates/blog/updateBlog src: templates/updateBlog
dest: /usr/local/bin/updateBlog dest: /usr/local/bin/updateBlog
mode: u+rx mode: u+rx
- name: Build blog
command:
cmd: updateBlog
register: blog_out
changed_when: blog_out.stdout != "up to date"
# Rebuild blog every hour # Rebuild blog every hour
- name: Setup blog cron job - name: Setup blog cron job
cron: cron:

View File

@@ -0,0 +1,32 @@
#!/bin/bash
cd /var/www/{{ domain }}
PUBLIC_DIR=public
TOR_DIR=tor
buildBlog () {
hugo --cleanDestinationDir --minify -d $PUBLIC_DIR -b https://{{ domain }}
hugo --cleanDestinationDir --minify -d $TOR_DIR -b {{ onionDomain }}
}
git fetch origin
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
# this string is hardcoded && checked by the 'Build blog' task
# to check for changes (changed_when)
echo "up to date"
elif [ $LOCAL = $BASE ]; then
# there are changes to reset too so we need to rebuild
echo "missing changes !!"
git reset --hard origin/main
buildBlog
fi
if [ ! -d "$PUBLIC_DIR" ] || [ ! -d "$TOR_DIR" ]; then
# probably first time setup
echo "missing directories !!"
buildBlog
fi

View File

@@ -2,7 +2,7 @@
cd $HOME/deadman cd $HOME/deadman
postPatch='../dead.patch' postPatch='dead.patch'
pageName='content/pages/dead.md' pageName='content/pages/dead.md'
currDate=$(date '+%Y-%m-%d') currDate=$(date '+%Y-%m-%d')
@@ -16,3 +16,5 @@ sed -i 's/--DATE--/'$currDate'/g' $pageName
git add . git add .
git commit -m "DeadSwitch: No response from CPunch in 14 days, posting dead.md" git commit -m "DeadSwitch: No response from CPunch in 14 days, posting dead.md"
git push --force git push --force
updateBlog

View File

@@ -6,13 +6,13 @@
- name: Install deadswitch script - name: Install deadswitch script
copy: copy:
src: static/blog/deadswitch src: deadswitch
dest: /usr/local/bin/deadswitch dest: /usr/local/bin/deadswitch
mode: u+rx mode: u+rx
- name: Install imdead.sh - name: Install imdead.sh
copy: copy:
src: static/blog/imdead.sh src: imdead.sh
dest: /root/deadman/imdead.sh dest: /root/deadman/imdead.sh
mode: u+rx mode: u+rx
@@ -22,6 +22,7 @@
dest: /root/deadman/dead.patch dest: /root/deadman/dead.patch
mode: u+rw mode: u+rw
# TODO: make idempotent
- name: Install deadtrigger - name: Install deadtrigger
file: file:
name: /root/.deadtrigger name: /root/.deadtrigger

View File

@@ -1,7 +1,9 @@
--- ---
# TODO: make idempotent
- name: Add Gitea repo key - name: Add Gitea repo key
shell: curl -s https://packaging.gitlab.io/gitea/gpg.key | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/morph027-gitea.gpg --import shell: curl -s https://packaging.gitlab.io/gitea/gpg.key | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/morph027-gitea.gpg --import
# TODO: make idempotent
- name: Set key perms - name: Set key perms
shell: sudo chmod 644 /etc/apt/trusted.gpg.d/morph027-gitea.gpg shell: sudo chmod 644 /etc/apt/trusted.gpg.d/morph027-gitea.gpg
@@ -30,6 +32,7 @@
- zsh # :D - zsh # :D
- python3-certbot-nginx - python3-certbot-nginx
# TODO: make idempotent
- name: Setup default shell (zsh) - name: Setup default shell (zsh)
shell: chsh -s /usr/bin/zsh shell: chsh -s /usr/bin/zsh
@@ -41,6 +44,6 @@
- name: Install .zshrc - name: Install .zshrc
copy: copy:
src: static/.zshrc src: .zshrc
dest: /root/.zshrc dest: /root/.zshrc
force: no force: no

View File

@@ -23,7 +23,7 @@
- name: Copy fail2ban jail config - name: Copy fail2ban jail config
copy: copy:
src: static/fail2ban/jails.local src: jails.local
dest: /etc/fail2ban/jail.d/jails.local dest: /etc/fail2ban/jail.d/jails.local
- name: Enable fail2ban service - name: Enable fail2ban service

View File

@@ -1,7 +1,7 @@
--- ---
- name: Setup git config - name: Setup git config
copy: copy:
src: static/.gitconfig src: .gitconfig
dest: /root/.gitconfig dest: /root/.gitconfig
owner: root owner: root
mode: u=rw,g=,o= mode: u=rw,g=,o=
@@ -9,6 +9,7 @@
# make sure our vps trusts the github.com key signature. we pipe the output # make sure our vps trusts the github.com key signature. we pipe the output
# of ssh-keyscan into .ssh/known_hosts # of ssh-keyscan into .ssh/known_hosts
# TODO: make idempotent
- name: Scan for SSH host keys - name: Scan for SSH host keys
command: ssh-keyscan github.com 2>/dev/null command: ssh-keyscan github.com 2>/dev/null
register: ssh_scan register: ssh_scan

View File

@@ -1,7 +1,7 @@
--- ---
- name: Configure Gitea - name: Configure Gitea
template: template:
src: templates/gitea/app.ini src: app.ini
dest: /etc/gitea/app.ini dest: /etc/gitea/app.ini
owner: gitea owner: gitea
force: no # we don't want to kill our existing config D: force: no # we don't want to kill our existing config D:

View File

@@ -1,5 +1,5 @@
--- ---
- name: Copy goaccess config - name: Copy goaccess config
copy: copy:
src: static/goaccess/goaccess.conf src: goaccess.conf
dest: /etc/goaccess/goaccess.conf dest: /etc/goaccess/goaccess.conf

View File

@@ -2,7 +2,7 @@ user www-data;
worker_processes auto; worker_processes auto;
include /etc/nginx/modules-enabled/*.conf; include /etc/nginx/modules-enabled/*.conf;
pid /run/nginx.pid; pid /run/nginx.pid;
events { events {
worker_connections 768; worker_connections 768;
} }

View File

@@ -0,0 +1,4 @@
---
- name: setup-nginx
include_tasks: setup.yml
listen: "setup nginx"

View File

@@ -0,0 +1,35 @@
---
- name: Install system nginx config
copy:
src: nginx.conf
dest: /etc/nginx/nginx.conf
notify: setup nginx
# setup our configs for each host (we don't want to
# overwrite certbot's changes, so if it already exists,
# don't copy!)
- name: Install nginx config for {{ domain }}
template:
src: templates/site.conf
dest: /etc/nginx/conf.d/{{ domain }}.conf
force: no
notify: setup nginx
- name: Install nginx config for git.{{ domain }}
template:
src: templates/gitea.conf
dest: /etc/nginx/conf.d/git.{{ domain }}.conf
force: no
notify: setup nginx
- name: Install nginx config for our Hidden Service
template:
src: templates/tor.conf
dest: /etc/nginx/conf.d/tor-{{ domain }}.conf
- name: Enable Nginx
systemd:
name: nginx
enabled: yes
state: started

View File

@@ -0,0 +1,9 @@
---
- name: Setup certbot
shell: "certbot --nginx --non-interactive --agree-tos -m {{ contact_email }} -d {{ domain }} -d git.{{ domain }}"
- name: Reload Nginx
systemd:
name: nginx
enabled: yes
state: restarted

View File

@@ -1,5 +1,5 @@
server { server {
root /var/www/{{ domain }}/public; root /var/www/{{ domain }}/tor;
index index.html index.htm; index index.html index.htm;
location / { location / {

View File

@@ -1,7 +1,7 @@
--- ---
- name: Install torrc - name: Install torrc
template: template:
src: templates/tor/torrc src: torrc
dest: /etc/tor/torrc dest: /etc/tor/torrc
owner: root owner: root
group: root group: root
@@ -23,7 +23,7 @@
group: debian-tor group: debian-tor
mode: u=rw,g=,o= mode: u=rw,g=,o=
- name: Reload Tor - name: Enable Tor Service
systemd: systemd:
name: tor name: tor
enabled: yes enabled: yes

20
run.yml
View File

@@ -9,13 +9,13 @@
prompt: domain pointing to the vps prompt: domain pointing to the vps
private: no private: no
tasks: roles:
- import_tasks: tasks/essential.yml - essential
- import_tasks: tasks/firewall.yml - git
- import_tasks: tasks/blog.yml - deadswitch
- import_tasks: tasks/gitea.yml - firewall
- import_tasks: tasks/tor.yml - blog
- import_tasks: tasks/nginx.yml - gitea
- import_tasks: tasks/git.yml - nginx
- import_tasks: tasks/goaccess.yml - goaccess
- import_tasks: tasks/deadswitch.yml - tor

Submodule secrets updated: 585d0fd7dd...e643deb62e

View File

@@ -1,52 +0,0 @@
---
- name: Remove default nginx config
file:
name: /etc/nginx/sites-enabled
state: absent
- name: Restore sites-enabled
file:
name: /etc/nginx/sites-enabled
state: directory
- name: Install system nginx config
copy:
src: static/nginx/nginx.conf
dest: /etc/nginx/nginx.conf
# setup our configs for each host (we don't want to
# overwrite certbot's changes, so if it already exists,
# don't copy!)
- name: Install nginx config for {{ domain }}
template:
src: templates/nginx/site.conf
dest: /etc/nginx/conf.d/{{ domain }}.conf
force: no
- name: Install nginx config for git.{{ domain }}
template:
src: templates/nginx/gitea.conf
dest: /etc/nginx/conf.d/git.{{ domain }}.conf
force: no
- name: Install nginx config for our Hidden Service
template:
src: templates/nginx/tor.conf
dest: /etc/nginx/conf.d/tor-{{ domain }}.conf
force: no
- name: Reload Nginx to install LetsEncrypt
service:
name: nginx
state: restarted
# certbot is a life saver. thank you certbot devs!
- name: Setup certbot
shell: "certbot --nginx --non-interactive --agree-tos -m {{ contact_email }} -d {{ domain }} -d git.{{ domain }}"
- name: Reload Nginx with LetsEncrypt installed
systemd:
name: nginx
enabled: yes
state: restarted

View File

@@ -1,5 +0,0 @@
#!/bin/bash
cd /var/www/{{ domain }}
/usr/bin/git fetch origin
/usr/bin/git reset --hard origin/main
/usr/bin/hugo