Compare commits
5 Commits
ed9100bc8f
...
209ff57a4a
Author | SHA1 | Date | |
---|---|---|---|
209ff57a4a | |||
9a4aece442 | |||
acd2cefb1e | |||
cd11567164 | |||
1c321f6ef7 |
3
Vagrantfile
vendored
3
Vagrantfile
vendored
@ -30,8 +30,9 @@ Vagrant.configure("2") do |config|
|
||||
config.vm.define :moxie do |moxie| #
|
||||
end
|
||||
|
||||
# Disable Machine Name Prefix
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.cpus = 2
|
||||
libvirt.memory = 4096
|
||||
libvirt.default_prefix = ""
|
||||
end
|
||||
|
||||
|
41
dev/host_vars/proxy.yml
Normal file
41
dev/host_vars/proxy.yml
Normal file
@ -0,0 +1,41 @@
|
||||
base_domain: vm.krislamo.org
|
||||
|
||||
# base
|
||||
allow_reboot: false
|
||||
manage_network: false
|
||||
|
||||
# proxy
|
||||
proxy:
|
||||
#production: true
|
||||
dns_cloudflare:
|
||||
opts: --test-cert
|
||||
#email: realemail@example.com
|
||||
#api_token: CLOUDFLARE_DNS01_API_TOKEN
|
||||
wildcard_domains:
|
||||
- "{{ base_domain }}"
|
||||
servers:
|
||||
- domain: "{{ bitwarden_domain }}"
|
||||
proxy_pass: "http://127.0.0.1:8080"
|
||||
- domain: "{{ gitea_domain }}"
|
||||
proxy_pass: "http://127.0.0.1:3080"
|
||||
|
||||
# docker
|
||||
docker_users:
|
||||
- vagrant
|
||||
|
||||
# bitwarden
|
||||
# Get Installation ID & Key at https://bitwarden.com/host/
|
||||
bitwarden_domain: "vault.{{ base_domain }}"
|
||||
bitwarden_dbpass: password
|
||||
bitwarden_install_id: 4ea840a3-532e-4cb6-a472-abd900728b23
|
||||
bitwarden_install_key: 1yB3Z2gRI0KnnH90C6p
|
||||
#bitwarden_prodution: true
|
||||
|
||||
# gitea
|
||||
gitea_domain: "git.{{ base_domain }}"
|
||||
gitea_version: 1
|
||||
gitea_dbversion: latest
|
||||
gitea_dbpass: password
|
||||
gitea_ports:
|
||||
- "222:22"
|
||||
- "3080:3000"
|
11
dev/proxy.yml
Normal file
11
dev/proxy.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- name: Install Proxy Server
|
||||
hosts: all
|
||||
become: true
|
||||
vars_files:
|
||||
- host_vars/proxy.yml
|
||||
roles:
|
||||
- base
|
||||
- proxy
|
||||
- docker
|
||||
- bitwarden
|
||||
- gitea
|
1
roles/.gitignore
vendored
1
roles/.gitignore
vendored
@ -11,6 +11,7 @@
|
||||
!nextcloud*/
|
||||
!nginx*/
|
||||
!prometheus*/
|
||||
!proxy*/
|
||||
!rsnapshot*/
|
||||
!traefik*/
|
||||
!unifi*/
|
||||
|
@ -1,4 +1,5 @@
|
||||
bitwarden_name: bitwarden
|
||||
bitwarden_root: "/opt/{{ bitwarden_name }}"
|
||||
bitwarden_database: "{{ bitwarden_name }}"
|
||||
bitwarden_standalone: false
|
||||
bitwarden_production: false
|
||||
|
@ -11,7 +11,7 @@
|
||||
- name: Download Bitwarden script
|
||||
get_url:
|
||||
url: "https://raw.githubusercontent.com/\
|
||||
bitwarden/server/master/scripts/bitwarden.sh"
|
||||
bitwarden/self-host/master/bitwarden.sh"
|
||||
dest: "{{ bitwarden_root }}"
|
||||
mode: u+x
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
template:
|
||||
src: compose.override.yml.j2
|
||||
dest: "{{ bitwarden_root }}/bwdata/docker/docker-compose.override.yml"
|
||||
when: traefik_version is defined
|
||||
notify:
|
||||
- rebuild_bitwarden
|
||||
- start_bitwarden
|
||||
|
@ -14,6 +14,9 @@ send "y\r"
|
||||
send "n\r"
|
||||
{% endif %}
|
||||
|
||||
expect "Enter the database name for your Bitwarden instance (ex. vault):"
|
||||
send "{{ bitwarden_database }}\r"
|
||||
|
||||
expect "Enter your installation id (get at https://bitwarden.com/host):"
|
||||
send "{{ bitwarden_install_id }}\r"
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
nginx:
|
||||
networks:
|
||||
|
@ -1 +0,0 @@
|
||||
deb [arch=amd64] https://download.docker.com/linux/debian buster stable
|
@ -1,38 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Github username and repo name
|
||||
user="docker"
|
||||
repo="compose"
|
||||
|
||||
# Retrieve the latest version number
|
||||
addr="https://github.com/$user/$repo/releases/latest"
|
||||
page=$(curl -s $addr | grep -o releases/tag/*.*\")
|
||||
version=$(echo $page | awk '{print substr($1, 14, length($1) - 14)}')
|
||||
|
||||
# Download prep
|
||||
url="https://github.com/$user/$repo/releases/download/$version"
|
||||
file="docker-compose-$(uname -s)-$(uname -m)"
|
||||
|
||||
# Download latest Docker Compose if that version hasn't been downloaded
|
||||
if [ ! -f /tmp/docker_compose_$version ]; then
|
||||
curl -L $url/$file -o /tmp/docker-compose_$version
|
||||
fi
|
||||
|
||||
# Is it already installed?
|
||||
if installed=$(which docker-compose); then
|
||||
|
||||
new_chksum=$(sha256sum /tmp/docker-compose_$version)
|
||||
old_chksum=$(sha256sum /usr/local/bin/docker-compose)
|
||||
|
||||
# If checksums are different, delete and install new version
|
||||
if [ ! "$new_chksum" = "$old_chksum" ]; then
|
||||
rm /usr/local/bin/docker-compose
|
||||
mv /tmp/docker-compose_$version /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
fi
|
||||
|
||||
else
|
||||
# It's not installed, so no need to remove
|
||||
mv /tmp/docker-compose_$version /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
fi
|
@ -1,43 +1,6 @@
|
||||
# Copyright (C) 2019 Kris Lamoureux
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
- name: Remove old versions of Docker
|
||||
- name: Install Docker
|
||||
apt:
|
||||
name: ['docker', 'docker-engine', 'docker.io', 'containerd', 'runc']
|
||||
state: absent
|
||||
update_cache: true
|
||||
|
||||
- name: Install HTTPS capability for apt
|
||||
apt:
|
||||
name: ['apt-transport-https', 'ca-certificates',
|
||||
'curl', 'gnupg2', 'software-properties-common']
|
||||
state: present
|
||||
|
||||
- name: Install Docker's signing key
|
||||
apt_key:
|
||||
url: https://download.docker.com/linux/debian/gpg
|
||||
id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
|
||||
state: present
|
||||
|
||||
- name: Install Docker's stable repository
|
||||
template:
|
||||
src: docker-ce.list
|
||||
dest: /etc/apt/sources.list.d/docker-ce.list
|
||||
|
||||
- name: Install Docker CE
|
||||
apt:
|
||||
name: ['docker-ce', 'docker-ce-cli', 'containerd.io']
|
||||
name: ['docker.io', 'docker-compose']
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
@ -49,11 +12,6 @@
|
||||
loop: "{{ docker_users }}"
|
||||
when: docker_users is defined
|
||||
|
||||
- name: Install docker-compose
|
||||
script: install-compose.sh
|
||||
args:
|
||||
creates: /usr/local/bin/docker-compose
|
||||
|
||||
- name: Start Docker and enable on boot
|
||||
service:
|
||||
name: docker
|
||||
|
@ -9,6 +9,7 @@
|
||||
state: started
|
||||
restart_policy: always
|
||||
volumes: "{{ gitea_dbroot }}:/var/lib/mysql"
|
||||
container_default_behavior: "no_defaults"
|
||||
networks_cli_compatible: true
|
||||
networks:
|
||||
- name: "{{ gitea_name }}"
|
||||
@ -18,12 +19,13 @@
|
||||
MYSQL_USER: "{{ gitea_dbuser }}"
|
||||
MYSQL_PASSWORD: "{{ gitea_dbpass }}"
|
||||
|
||||
- name: Start Gitea container
|
||||
- name: Start Gitea container (traefik routing)
|
||||
docker_container:
|
||||
name: "{{ gitea_name }}"
|
||||
image: gitea/gitea:{{ gitea_version }}
|
||||
state: started
|
||||
restart_policy: always
|
||||
container_default_behavior: "no_defaults"
|
||||
networks_cli_compatible: true
|
||||
ports: "{{ gitea_ports }}"
|
||||
networks:
|
||||
@ -52,3 +54,32 @@
|
||||
traefik.http.services.gitea.loadbalancer.server.port: "3000"
|
||||
traefik.docker.network: traefik
|
||||
traefik.enable: "true"
|
||||
when: traefik_version is defined
|
||||
|
||||
- name: Start Gitea container
|
||||
docker_container:
|
||||
name: "{{ gitea_name }}"
|
||||
image: gitea/gitea:{{ gitea_version }}
|
||||
state: started
|
||||
restart_policy: always
|
||||
container_default_behavior: "no_defaults"
|
||||
networks_cli_compatible: true
|
||||
ports: "{{ gitea_ports }}"
|
||||
networks:
|
||||
- name: "{{ gitea_name }}"
|
||||
volumes:
|
||||
- "{{ gitea_root }}:/data"
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
env:
|
||||
USER_UID: "1000"
|
||||
USER_GID: "1000"
|
||||
DB_TYPE: mysql
|
||||
DB_HOST: "{{ gitea_dbname }}"
|
||||
DB_NAME: "{{ gitea_dbname }}"
|
||||
DB_USER: "{{ gitea_dbuser }}"
|
||||
DB_PASSWD: "{{ gitea_dbpass }}"
|
||||
ROOT_URL: "https://{{ gitea_domain }}/"
|
||||
SSH_DOMAIN: "{{ gitea_domain }}"
|
||||
DOMAIN: "{{ gitea_domain }}"
|
||||
when: traefik_version is not defined
|
||||
|
2
roles/proxy/files/reload-nginx.sh
Normal file
2
roles/proxy/files/reload-nginx.sh
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
systemctl reload nginx
|
5
roles/proxy/handlers/main.yml
Normal file
5
roles/proxy/handlers/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: Reload nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
listen: reload_nginx
|
85
roles/proxy/tasks/main.yml
Normal file
85
roles/proxy/tasks/main.yml
Normal file
@ -0,0 +1,85 @@
|
||||
- name: Install nginx
|
||||
apt:
|
||||
name: nginx
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Start nginx and enable on boot
|
||||
service:
|
||||
name: nginx
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
- name: Install nginx base configuration
|
||||
template:
|
||||
src: nginx.conf.j2
|
||||
dest: /etc/nginx/nginx.conf
|
||||
mode: '0644'
|
||||
notify: reload_nginx
|
||||
|
||||
- name: Install nginx sites configuration
|
||||
template:
|
||||
src: server-nginx.conf.j2
|
||||
dest: "/etc/nginx/sites-available/{{ item.domain }}.conf"
|
||||
mode: '0644'
|
||||
loop: "{{ proxy.servers }}"
|
||||
notify: reload_nginx
|
||||
register: nginx_sites
|
||||
|
||||
- name: Enable nginx sites configuration
|
||||
file:
|
||||
src: "/etc/nginx/sites-available/{{ item.item.domain }}.conf"
|
||||
dest: "/etc/nginx/sites-enabled/{{ item.item.domain }}.conf"
|
||||
state: link
|
||||
loop: "{{ nginx_sites.results }}"
|
||||
when: item.changed
|
||||
notify: reload_nginx
|
||||
|
||||
- name: Generate self-signed certificate
|
||||
shell: 'openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes \
|
||||
-subj "/C=US/ST=Local/L=Local/O=Org/OU=IT/CN=example.com" \
|
||||
-keyout /etc/ssl/private/nginx-selfsigned.key \
|
||||
-out /etc/ssl/certs/nginx-selfsigned.crt'
|
||||
args:
|
||||
creates: /etc/ssl/certs/nginx-selfsigned.crt
|
||||
when: proxy.production is not defined or not proxy.production
|
||||
notify: reload_nginx
|
||||
|
||||
- name: Install LE's certbot
|
||||
apt:
|
||||
name: ['certbot', 'python3-certbot-dns-cloudflare']
|
||||
state: present
|
||||
when: proxy.production is defined and proxy.production
|
||||
|
||||
- name: Install Cloudflare API token
|
||||
template:
|
||||
src: cloudflare.ini.j2
|
||||
dest: /root/.cloudflare.ini
|
||||
mode: '0600'
|
||||
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
|
||||
|
||||
- name: Create nginx post renewal hook directory
|
||||
file:
|
||||
path: /etc/letsencrypt/renewal-hooks/post
|
||||
state: directory
|
||||
|
||||
- name: Install nginx post renewal hook
|
||||
copy:
|
||||
src: reload-nginx.sh
|
||||
dest: /etc/letsencrypt/renewal-hooks/post/reload-nginx.sh
|
||||
mode: '0755'
|
||||
when: proxy.production is defined and proxy.production
|
||||
|
||||
- name: Run Cloudflare DNS-01 challenges on wildcard domains
|
||||
shell: '/usr/bin/certbot certonly \
|
||||
--non-interactive \
|
||||
--agree-tos \
|
||||
--email "{{ proxy.dns_cloudflare.email }}" \
|
||||
--dns-cloudflare \
|
||||
--dns-cloudflare-credentials /root/.cloudflare.ini \
|
||||
-d "*.{{ item }}" {{ proxy.dns_cloudflare.opts | default("") }}'
|
||||
args:
|
||||
creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem"
|
||||
loop: "{{ proxy.dns_cloudflare.wildcard_domains }}"
|
||||
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
|
||||
notify: reload_nginx
|
2
roles/proxy/templates/cloudflare.ini.j2
Normal file
2
roles/proxy/templates/cloudflare.ini.j2
Normal file
@ -0,0 +1,2 @@
|
||||
# Cloudflare API token used by Certbot
|
||||
dns_cloudflare_api_token = {{ proxy.dns_cloudflare.api_token }}
|
26
roles/proxy/templates/nginx.conf.j2
Normal file
26
roles/proxy/templates/nginx.conf.j2
Normal file
@ -0,0 +1,26 @@
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log;
|
||||
pid /run/nginx.pid;
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
log_format main '$remote_addr - $remote_user [$time_local] $status '
|
||||
'"$request" $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
access_log /var/log/nginx/access.log main;
|
||||
server_tokens off;
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
keepalive_timeout 65;
|
||||
server_names_hash_bucket_size 128;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
28
roles/proxy/templates/server-nginx.conf.j2
Normal file
28
roles/proxy/templates/server-nginx.conf.j2
Normal file
@ -0,0 +1,28 @@
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name {{ item.domain }};
|
||||
access_log /var/log/nginx/{{ item.domain }}.log main;
|
||||
{% if proxy.production is defined and proxy.production and proxy.dns_cloudflare.wildcard_domains is defined and item.tls.cert is not defined %}
|
||||
{% for wildcard in proxy.dns_cloudflare.wildcard_domains %}
|
||||
{% set domain_regex = '^\*\.' + wildcard + '$' %}
|
||||
{% if item.domain | regex_search(wildcard) %}
|
||||
ssl_certificate /etc/letsencrypt/live/{{ wildcard }}/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/{{ wildcard }}/privkey.pem;
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% elif proxy.production is defined and proxy.production and item.tls.cert is not defined %}
|
||||
ssl_certificate /etc/letsencrypt/live/{{ item.domain }}/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/{{ item.domain }}/privkey.pem;
|
||||
{% elif proxy.production is defined and proxy.production and item.tls.cert is defined %}
|
||||
ssl_certificate {{ item.tls.cert }};
|
||||
ssl_certificate_key {{ item.tls.key }};
|
||||
{% else %}
|
||||
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
|
||||
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
|
||||
{% endif %}
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_pass {{ item.proxy_pass }};
|
||||
}
|
||||
}
|
@ -9,5 +9,6 @@
|
||||
name: "{{ traefik_name }}"
|
||||
image: traefik:{{ traefik_version }}
|
||||
state: started
|
||||
container_default_behavior: "no_defaults"
|
||||
restart: yes
|
||||
listen: restart_traefik
|
||||
|
@ -36,6 +36,7 @@
|
||||
state: started
|
||||
restart_policy: always
|
||||
ports: "{{ traefik_ports }}"
|
||||
container_default_behavior: "no_defaults"
|
||||
networks_cli_compatible: "false"
|
||||
networks:
|
||||
- name: traefik
|
||||
|
Loading…
Reference in New Issue
Block a user