1 Commits

Author SHA1 Message Date
e8b1c433e9 testing 2022-12-19 02:25:17 -05:00
22 changed files with 108 additions and 241 deletions

View File

@@ -1,25 +1,39 @@
# Project Moxie
# Homelab
This repository contains Ansible to automate Debian GNU/Linux servers, deploying
server technologies that are either useful in a personal capacity or provide
educational value on automating enterprise infrastructure.
Project Moxie is a personal IT homelab project written in Ansible and executed by Jenkins. It is a growing collection of infrastructure as code (IaC) I write out of curiosity and for reference purposes, keeping a handful of beneficial projects managed and secured.
Development is accomplished using Vagrant to allow easy reproducibility in an
isolated virtual environment that be ran on your local machine.
## Quick Start
To configure a local virtual machine for testing, follow these simple steps.
These steps assume a basic understanding of GNU/Linux, Hypervisors, Vagrant, and Ansible.
### Prerequisites
Vagrant and VirtualBox are used to develop Project Moxie. You will need to install these before continuing.
- [Vagrant](https://developer.hashicorp.com/vagrant/docs/installation)
- [Supported hypervisor](https://developer.hashicorp.com/vagrant/docs/providers)
- Ansible
### Installation
1. Clone this repository
```
git clone https://github.com/krislamo/moxie
git clone https://git.krislamo.org/kris/homelab
```
OR download from the mirror on GitHub:
```
git clone https://github.com/krislamo/homelab
```
2. Set the `PLAYBOOK` environmental variable to a development playbook name in the `dev/` directory
The following `PLAYBOOK` names are available: `dockerbox`, `hypervisor`, `minecraft`, `bitwarden`, `nextcloud`, `nginx`
2. Find available playbooks for development
```
cd homelab
```
```
find dev -maxdepth 1 -name "*.yml" -exec basename {} .yml \;
```
3. Set the `PLAYBOOK` environmental variable to a value listed in the last step, e.g.,
```
export PLAYBOOK=dockerbox
```
@@ -29,11 +43,10 @@ Vagrant and VirtualBox are used to develop Project Moxie. You will need to insta
```
#### Copyright and License
Copyright (C) 2020-2021 Kris Lamoureux
Copyright (C) 2020-2022 Kris Lamoureux
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
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.

View File

@@ -8,6 +8,7 @@
- docker
- traefik
- nextcloud
- gitea
- jenkins
- prometheus
- nginx

View File

@@ -13,7 +13,6 @@ traefik_domain: traefik.vm.krislamo.org
traefik_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
#traefik_acme_email: realemail@example.com # Let's Encrypt settings
#traefik_production: true
traefik_http_only: true # if behind reverse-proxy
# nextcloud
nextcloud_version: stable

View File

@@ -1,37 +0,0 @@
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: "{{ traefik_domain }}"
proxy_pass: "http://127.0.0.1:8000"
- domain: "{{ jellyfin_domain }}"
proxy_pass: "http://127.0.0.1:8000"
# docker
docker_users:
- vagrant
# traefik
traefik_version: latest
traefik_dashboard: true
traefik_domain: "traefik.{{ base_domain }}"
traefik_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
#traefik_acme_email: realemail@example.com # Let's Encrypt settings
#traefik_production: true
traefik_http_only: true # if behind reverse-proxy
# jellyfin
jellyfin_domain: "jellyfin.{{ base_domain }}"
jellyfin_version: latest

View File

@@ -1,11 +0,0 @@
- name: Install Media Server
hosts: all
become: true
vars_files:
- host_vars/mediaserver.yml
roles:
- base
- proxy
- docker
- traefik
- jellyfin

View File

@@ -1,9 +0,0 @@
- name: Install Media Server
hosts: mediaservers
become: true
roles:
- base
- proxy
- docker
- traefik
- jellyfin

20
roles/.gitignore vendored Normal file
View File

@@ -0,0 +1,20 @@
/*
!.gitignore
!requirements.yml
!base*/
!bitwarden*/
!docker*/
!gitea*/
!jenkins*/
!libvirt*/
!mariadb*/
!minecraft*/
!nextcloud*/
!nginx*/
!postgresql*/
!prometheus*/
!proxy*/
!rsnapshot*/
!traefik*/
!unifi*/
!wordpress*/

View File

@@ -1,24 +1,18 @@
- name: Reboot host
ansible.builtin.reboot:
reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
listen: reboot_host
when: allow_reboot
- name: Restart WireGuard
ansible.builtin.service:
service:
name: wg-quick@wg0
state: restarted
listen: restart_wireguard
- name: Restart Fail2ban
ansible.builtin.service:
service:
name: fail2ban
state: restarted
listen: restart_fail2ban
- name: Restart ddclient
ansible.builtin.service:
name: ddclient
state: restarted
listen: restart_ddclient

View File

@@ -1,11 +1,11 @@
- name: 'Install Ansible dependency: python3-apt'
ansible.builtin.shell: 'apt-get update && apt-get install python3-apt -y'
shell: 'apt-get update && apt-get install python3-apt -y'
args:
creates: /usr/lib/python3/dist-packages/apt
warn: false
- name: Install additional Ansible dependencies
ansible.builtin.apt:
apt:
name: "{{ item }}"
state: present
force_apt_get: true
@@ -17,7 +17,7 @@
- python3-psycopg2
- name: Create Ansible's temporary remote directory
ansible.builtin.file:
file:
path: "~/.ansible/tmp"
state: directory
mode: 0700

View File

@@ -1,17 +1,22 @@
- name: Install ddclient
ansible.builtin.apt:
apt:
name: ddclient
state: present
- name: Install ddclient settings
ansible.builtin.template:
template:
src: ddclient.conf.j2
dest: /etc/ddclient.conf
mode: 0600
register: ddclient_settings
- name: Start ddclient and enable on boot
ansible.builtin.service:
service:
name: ddclient
state: started
enabled: true
- name: Restart ddclient
service:
name: ddclient
state: restarted
when: ddclient_settings.changed

View File

@@ -1,5 +0,0 @@
jellyfin_name: jellyfin
jellyfin_volume: "{{ jellyfin_name }}"
jellyfin_router: "{{ jellyfin_name }}"
jellyfin_rooturl: "https://{{ jellyfin_domain }}"
jellyfin_root: "{{ docker_compose_root }}/{{ jellyfin_name }}"

View File

@@ -1,5 +0,0 @@
- name: Restart Jellyfin
service:
name: "{{ docker_compose_service }}@{{ jellyfin_name }}"
state: restarted
listen: restart_jellyfin

View File

@@ -1,37 +0,0 @@
- name: Create Jellyfin directory
ansible.builtin.file:
path: "{{ jellyfin_root }}"
state: directory
- name: Create jellyfin user
user:
name: jellyfin
state: present
- name: jellyfin user uid
getent:
database: passwd
key: jellyfin
- name: jellyfin user gid
getent:
database: group
key: jellyfin
- name: Install Jellyfin's docker-compose file
template:
src: docker-compose.yml.j2
dest: "{{ jellyfin_root }}/docker-compose.yml"
notify: restart_jellyfin
- name: Install Jellyfin's docker-compose variables
template:
src: compose-env.j2
dest: "{{ jellyfin_root }}/.env"
notify: restart_jellyfin
- name: Start and enable Jellyfin service
service:
name: "{{ docker_compose_service }}@{{ jellyfin_name }}"
state: started
enabled: true

View File

@@ -1,5 +0,0 @@
# {{ ansible_managed }}
jellyfin_version={{ jellyfin_version }}
jellyfin_name={{ jellyfin_name }}
jellyfin_domain={{ jellyfin_domain }}
jellyfin_rooturl={{ jellyfin_rooturl }}

View File

@@ -1,29 +0,0 @@
version: '3.7'
volumes:
{{ jellyfin_volume }}:
networks:
traefik:
external: true
services:
jellyfin:
image: "jellyfin/jellyfin:${jellyfin_version}"
container_name: "${jellyfin_name}"
networks:
- traefik
labels:
- "traefik.http.routers.{{ jellyfin_router }}.rule=Host(`{{ jellyfin_domain }}`)"
{% if traefik_http_only %}
- "traefik.http.routers.{{ jellyfin_router }}.entrypoints=web"
{% else %}
- "traefik.http.routers.{{ jellyfin_router }}.entrypoints=websecure"
{% endif %}
- "traefik.http.services.{{ jellyfin_router }}.loadbalancer.server.port=8096"
- "traefik.docker.network=traefik"
- "traefik.enable=true"
volumes:
- ./config:/config
- ./cache:/cache
- {{ jellyfin_volume }}:/media

View File

@@ -1,18 +1,12 @@
# Container settings
traefik_name: traefik
traefik_standalone: true
traefik_http_only: false
traefik_debug: false
traefik_web_entry: "127.0.0.1:8000"
traefik_websecure_entry: "127.0.0.1:8443"
traefik_dashboard: false
traefik_root: "/opt/{{ traefik_name }}"
traefik_localonly: "10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8"
# HTTPS settings
traefik_production: false
traefik_hsts_enable: false
traefik_hsts_preload: false
traefik_hsts_seconds: 0
traefik_http_redirect: true
# Host settings
traefik_root: "{{ docker_compose_root }}/{{ traefik_name }}"
traefik_http_redirect: false
traefik_ports:
- "80:80"
- "443:443"

View File

@@ -4,8 +4,11 @@
state: touch
listen: reload_traefik
- name: Restart Traefik
service:
name: "{{ docker_compose_service }}@{{ traefik_name }}"
state: restarted
- name: Restart Traefik container
docker_container:
name: "{{ traefik_name }}"
image: traefik:{{ traefik_version }}
state: started
container_default_behavior: "no_defaults"
restart: yes
listen: restart_traefik

View File

@@ -1,8 +1,14 @@
- name: Create Traefik directories
- name: Create Traefik configuration directories
file:
path: "{{ traefik_root }}/config/dynamic"
state: directory
- name: Install static Traefik configuration
template:
src: traefik.yml.j2
dest: "{{ traefik_root }}/config/traefik.yml"
notify: restart_traefik
- name: Install dynamic security configuration
template:
src: security.yml.j2
@@ -19,26 +25,32 @@
loop: "{{ traefik_external }}"
when: traefik_external is defined
- name: Install Traefik's docker-compose file
template:
src: docker-compose.yml.j2
dest: "{{ traefik_root }}/docker-compose.yml"
notify: restart_traefik
- name: Create Traefik network
docker_network:
name: traefik
- name: Install Traefik's docker-compose variables
template:
src: compose-env.j2
dest: "{{ traefik_root }}/.env"
notify: restart_traefik
- name: Install static Traefik configuration
template:
src: traefik.yml.j2
dest: "{{ traefik_root }}/config/traefik.yml"
notify: restart_traefik
- name: Start and enable Traefik service
service:
name: "{{ docker_compose_service }}@{{ traefik_name }}"
- name: Start Traefik container
docker_container:
name: "{{ traefik_name }}"
image: traefik:{{ traefik_version }}
state: started
enabled: true
restart_policy: always
ports: "{{ traefik_ports }}"
container_default_behavior: "no_defaults"
networks_cli_compatible: "false"
networks:
- name: traefik
labels:
traefik.http.routers.traefik.rule: "Host(`{{ traefik_domain }}`)"
#traefik.http.middlewares.auth.basicauth.users: "{{ traefik_auth }}"
#traefik.http.middlewares.localonly.ipwhitelist.sourcerange: "{{ traefik_localonly }}"
#traefik.http.routers.traefik.tls.certresolver: letsencrypt
#traefik.http.routers.traefik.middlewares: "securehttps@file,auth@docker,localonly"
traefik.http.routers.traefik.service: "api@internal"
traefik.http.routers.traefik.entrypoints: websecure
traefik.http.routers.traefik.tls: "true"
traefik.docker.network: traefik
traefik.enable: "{{ traefik_dashboard | string }}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- "{{ traefik_root }}/config:/etc/traefik"

View File

@@ -1,8 +0,0 @@
# {{ ansible_managed }}
traefik_version={{ traefik_version }}
traefik_name={{ traefik_name }}
traefik_domain={{ traefik_domain }}
traefik_dashboard={{ traefik_dashboard | string | lower }}
traefik_debug={{ traefik_debug | string | lower }}
traefik_web_entry={{ traefik_web_entry }}
traefik_websecure_entry={{ traefik_websecure_entry }}

View File

@@ -1,25 +0,0 @@
version: '3.7'
networks:
traefik:
name: traefik
services:
traefik:
image: "traefik:${traefik_version}"
container_name: "${traefik_name}"
ports:
- "${traefik_web_entry}:80"
{% if traefik_standalone and not traefik_http_only %}
- "${traefik_websecure_entry}:443"
{% endif %}
networks:
- traefik
labels:
- "traefik.http.routers.traefik.rule=Host(`{{ traefik_domain }}`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.docker.network=traefik"
- "traefik.enable=${traefik_dashboard}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- "{{ traefik_root }}/config:/etc/traefik"

View File

@@ -10,7 +10,7 @@ providers:
entrypoints:
web:
address: ':80'
{% if traefik_http_redirect is defined and traefik_http_redirect and not traefik_http_only %}
{% if traefik_http_redirect is defined and traefik_http_redirect %}
http:
redirections:
entrypoint:
@@ -18,12 +18,10 @@ entrypoints:
scheme: https
permanent: true
{% endif %}
{% if not traefik_http_only is defined or not traefik_http_only %}
websecure:
address: ':443'
http:
tls: {}
{% endif %}
{% if traefik_acme_email is defined %}
certificatesResolvers:

View File

@@ -14,7 +14,6 @@ HOST[8]="wordpress.${DOMAIN}"
HOST[9]="site1.wordpress.${DOMAIN}"
HOST[10]="site2.wordpress.${DOMAIN}"
HOST[11]="unifi.${DOMAIN}"
HOST[12]="jellyfin.${DOMAIN}"
# Get Vagrantbox guest IP
VAGRANT_OUTPUT=$(vagrant ssh -c "hostname -I | cut -d' ' -f2" 2>/dev/null)