Compare commits
1 Commits
7c2def16a5
...
c46c763c1f
Author | SHA1 | Date | |
---|---|---|---|
c46c763c1f |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
.playbook
|
||||
.vagrant*
|
||||
.vagrant
|
||||
.vscode
|
||||
/environments/
|
10
Makefile
10
Makefile
@ -1,10 +0,0 @@
|
||||
.PHONY: clean install
|
||||
|
||||
all: install
|
||||
|
||||
install:
|
||||
vagrant up --no-destroy-on-error
|
||||
sudo ./forward-ssh.sh
|
||||
|
||||
clean:
|
||||
vagrant destroy -f && rm -rf .vagrant
|
50
Vagrantfile
vendored
50
Vagrantfile
vendored
@ -1,41 +1,43 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
require 'yaml'
|
||||
settings_path = '.vagrant.yml'
|
||||
settings = {}
|
||||
|
||||
if File.exist?(settings_path)
|
||||
settings = YAML.load_file(settings_path)
|
||||
SSH_FORWARD=ENV["SSH_FORWARD"]
|
||||
if !(SSH_FORWARD == "true")
|
||||
SSH_FORWARD = false
|
||||
end
|
||||
|
||||
VAGRANT_BOX = settings['VAGRANT_BOX'] || 'debian/bookworm64'
|
||||
VAGRANT_CPUS = settings['VAGRANT_CPUS'] || 2
|
||||
VAGRANT_MEM = settings['VAGRANT_MEM'] || 2048
|
||||
SSH_FORWARD = settings['SSH_FORWARD'] || false
|
||||
|
||||
# Default to shell environment variable: PLAYBOOK (priority #1)
|
||||
PLAYBOOK=ENV["PLAYBOOK"]
|
||||
if !PLAYBOOK
|
||||
if File.exist?('.playbook')
|
||||
PLAYBOOK = IO.read('.playbook').split("\n")[0]
|
||||
end
|
||||
|
||||
if !PLAYBOOK || PLAYBOOK.empty?
|
||||
# PLAYBOOK setting in .vagrant.yml (priority #2)
|
||||
PLAYBOOK = settings['PLAYBOOK'] || 'default'
|
||||
PLAYBOOK = "\nERROR: Set env PLAYBOOK"
|
||||
end
|
||||
else
|
||||
File.write(".playbook", PLAYBOOK)
|
||||
end
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = VAGRANT_BOX
|
||||
config.vm.box = "debian/bullseye64"
|
||||
config.vm.network "private_network", type: "dhcp"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.synced_folder "./scratch", "/vagrant/scratch"
|
||||
config.ssh.forward_agent = SSH_FORWARD
|
||||
|
||||
# Libvrit provider
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.cpus = VAGRANT_CPUS
|
||||
libvirt.memory = VAGRANT_MEM
|
||||
# Machine Name
|
||||
config.vm.define :moxie do |moxie| #
|
||||
end
|
||||
|
||||
# Virtualbox provider
|
||||
config.vm.provider :virtualbox do |vbox|
|
||||
vbox.cpus = VAGRANT_CPUS
|
||||
vbox.memory = VAGRANT_MEM
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.cpus = 2
|
||||
libvirt.memory = 4096
|
||||
libvirt.default_prefix = ""
|
||||
end
|
||||
|
||||
config.vm.provider "virtualbox" do |vbox|
|
||||
vbox.memory = 4096
|
||||
end
|
||||
|
||||
# Provision with Ansible
|
||||
@ -43,6 +45,6 @@ Vagrant.configure("2") do |config|
|
||||
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
|
||||
ansible.compatibility_mode = "2.0"
|
||||
ansible.playbook = "dev/" + PLAYBOOK + ".yml"
|
||||
ansible.raw_arguments = ["--diff"]
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,7 +1,6 @@
|
||||
[defaults]
|
||||
inventory = ./environments/development
|
||||
interpreter_python = /usr/bin/python3
|
||||
roles_path = ./roles
|
||||
|
||||
[connection]
|
||||
pipelining = true
|
||||
|
@ -1,4 +0,0 @@
|
||||
- name: Install 'default' aka nothing
|
||||
hosts: all
|
||||
become: true
|
||||
tasks: []
|
@ -1,4 +1,4 @@
|
||||
- name: Install Dockerbox Server
|
||||
- name: Install Docker Box Server
|
||||
hosts: all
|
||||
become: true
|
||||
vars_files:
|
||||
|
@ -9,14 +9,14 @@ docker_users:
|
||||
# traefik
|
||||
traefik_version: latest
|
||||
traefik_dashboard: true
|
||||
traefik_domain: traefik.local.krislamo.org
|
||||
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
|
||||
|
||||
# bitwarden
|
||||
# Get Installation ID & Key at https://bitwarden.com/host/
|
||||
bitwarden_domain: vault.local.krislamo.org
|
||||
bitwarden_domain: vault.vm.krislamo.org
|
||||
bitwarden_dbpass: password
|
||||
bitwarden_install_id: 4ea840a3-532e-4cb6-a472-abd900728b23
|
||||
bitwarden_install_key: 1yB3Z2gRI0KnnH90C6p
|
||||
|
@ -6,34 +6,8 @@ manage_network: false
|
||||
docker_users:
|
||||
- vagrant
|
||||
|
||||
#docker_login_url: https://myregistry.example.com
|
||||
#docker_login_user: myuser
|
||||
#docker_login_pass: YOUR_PASSWD
|
||||
|
||||
docker_compose_deploy:
|
||||
- name: traefik
|
||||
url: https://github.com/krislamo/traefik
|
||||
version: 4d3391b1644e87dec2d60d3315401e4db2bbc943
|
||||
enabled: true
|
||||
accept_newhostkey: true # Consider verifying manually instead
|
||||
# Must manually add my GPG key to root's keyring
|
||||
#trusted_keys:
|
||||
# - FBF673CEEC030F8AECA814E73EDA9C3441EDA925
|
||||
env:
|
||||
VERSION: "2.10"
|
||||
- name: traefik2
|
||||
url: https://github.com/krislamo/traefik
|
||||
version: 4d3391b1644e87dec2d60d3315401e4db2bbc943
|
||||
enabled: true
|
||||
accept_newhostkey: true # Consider verifying manually instead
|
||||
# Must manually add my GPG key to root's keyring
|
||||
#trusted_keys:
|
||||
# - FBF673CEEC030F8AECA814E73EDA9C3441EDA925
|
||||
env:
|
||||
VERSION: "2.10"
|
||||
DOMAIN: traefik2.local.krislamo.org
|
||||
ROUTER: traefik2
|
||||
NETWORK: traefik2
|
||||
WEB_PORT: 127.0.0.1:8000:80
|
||||
WEBSECURE_PORT: 127.0.0.1:4443:443
|
||||
LOCAL_POST: 127.0.0.1:8444:8443
|
||||
- name: docs
|
||||
url: git@git.krislamo.org:kris/homelab-docs.git
|
||||
version: main
|
||||
sync: true
|
||||
|
@ -9,36 +9,40 @@ docker_users:
|
||||
# traefik
|
||||
traefik_version: latest
|
||||
traefik_dashboard: true
|
||||
traefik_domain: traefik.local.krislamo.org
|
||||
traefik_domain: traefik.vm.krislamo.org
|
||||
traefik_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
|
||||
traefik_web_entry: 0.0.0.0:80
|
||||
traefik_websecure_entry: 0.0.0.0:443
|
||||
#traefik_acme_email: realemail@example.com # Let's Encrypt settings
|
||||
#traefik_production: true
|
||||
#traefik_http_only: true # if behind reverse-proxy
|
||||
traefik_http_only: true # if behind reverse-proxy
|
||||
|
||||
# nextcloud
|
||||
nextcloud_version: stable
|
||||
nextcloud_admin: admin
|
||||
nextcloud_pass: password
|
||||
nextcloud_domain: cloud.local.krislamo.org
|
||||
nextcloud_domain: cloud.vm.krislamo.org
|
||||
|
||||
nextcloud_dbversion: latest
|
||||
nextcloud_dbpass: password
|
||||
|
||||
# gitea
|
||||
gitea_domain: git.vm.krislamo.org
|
||||
gitea_version: 1
|
||||
gitea_dbversion: latest
|
||||
gitea_dbpass: password
|
||||
|
||||
# jenkins
|
||||
jenkins_version: lts
|
||||
jenkins_domain: jenkins.local.krislamo.org
|
||||
jenkins_domain: jenkins.vm.krislamo.org
|
||||
|
||||
# prometheus (includes grafana)
|
||||
prom_version: latest
|
||||
prom_domain: prom.local.krislamo.org
|
||||
prom_domain: prom.vm.krislamo.org
|
||||
grafana_version: latest
|
||||
grafana_domain: grafana.local.krislamo.org
|
||||
grafana_domain: grafana.vm.krislamo.org
|
||||
prom_targets: "['10.0.2.15:9100']"
|
||||
|
||||
# nginx
|
||||
nginx_domain: nginx.local.krislamo.org
|
||||
nginx_domain: nginx.vm.krislamo.org
|
||||
nginx_name: staticsite
|
||||
nginx_repo_url: https://git.krislamo.org/kris/example-website/
|
||||
nginx_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
|
||||
|
@ -1,4 +1,4 @@
|
||||
base_domain: local.krislamo.org
|
||||
base_domain: vm.krislamo.org
|
||||
|
||||
# base
|
||||
allow_reboot: false
|
||||
|
@ -5,14 +5,14 @@ docker_users:
|
||||
# traefik
|
||||
traefik_version: latest
|
||||
traefik_dashboard: true
|
||||
traefik_domain: traefik.local.krislamo.org
|
||||
traefik_domain: traefik.vm.krislamo.org
|
||||
traefik_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
|
||||
|
||||
# container settings
|
||||
nextcloud_version: stable
|
||||
nextcloud_admin: admin
|
||||
nextcloud_pass: password
|
||||
nextcloud_domain: cloud.local.krislamo.org
|
||||
nextcloud_domain: cloud.vm.krislamo.org
|
||||
|
||||
# database settings
|
||||
nextcloud_dbversion: latest
|
||||
|
@ -9,13 +9,13 @@ docker_users:
|
||||
# traefik
|
||||
traefik_version: latest
|
||||
traefik_dashboard: true
|
||||
traefik_domain: traefik.local.krislamo.org
|
||||
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
|
||||
|
||||
# nginx
|
||||
nginx_domain: nginx.local.krislamo.org
|
||||
nginx_domain: nginx.vm.krislamo.org
|
||||
nginx_name: staticsite
|
||||
nginx_repo_url: https://git.krislamo.org/kris/example-website/
|
||||
nginx_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
|
||||
|
@ -1,4 +1,4 @@
|
||||
base_domain: local.krislamo.org
|
||||
base_domain: vm.krislamo.org
|
||||
|
||||
# base
|
||||
allow_reboot: false
|
||||
|
@ -9,14 +9,14 @@ docker_users:
|
||||
# traefik
|
||||
traefik_version: latest
|
||||
traefik_dashboard: true
|
||||
traefik_domain: traefik.local.krislamo.org
|
||||
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
|
||||
|
||||
# container settings
|
||||
wordpress_version: latest
|
||||
wordpress_domain: wordpress.local.krislamo.org
|
||||
wordpress_domain: wordpress.vm.krislamo.org
|
||||
wordpress_multisite: true
|
||||
|
||||
# database settings
|
||||
|
25
dockerbox.yml
Normal file
25
dockerbox.yml
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (C) 2020 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: Install Docker Box Server
|
||||
hosts: dockerhosts
|
||||
become: true
|
||||
roles:
|
||||
- base
|
||||
- docker
|
||||
- traefik
|
||||
- nextcloud
|
||||
- jenkins
|
||||
- prometheus
|
||||
- nginx
|
@ -1,90 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Finds the SSH private key under ./.vagrant and connects to
|
||||
# the Vagrant box, port forwarding localhost ports: 8443, 80, 443
|
||||
|
||||
# Root check
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "[ERROR]: Please run script as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean environment
|
||||
unset PRIVATE_KEY
|
||||
unset HOST_IP
|
||||
unset MATCH_PATTERN
|
||||
unset PKILL_ANSWER
|
||||
|
||||
# Function to create the SSH tunnel
|
||||
function ssh_connect {
|
||||
read -rp "Start a new vagrant SSH tunnel? [y/N] " PSTART_ANSWER
|
||||
echo
|
||||
case "$PSTART_ANSWER" in
|
||||
[yY])
|
||||
printf "[INFO]: Starting new vagrant SSH tunnel on PID "
|
||||
sudo -u "$USER" ssh -fNT -i "$PRIVATE_KEY" \
|
||||
-L 8443:localhost:8443 \
|
||||
-L 80:localhost:80 \
|
||||
-L 443:localhost:443 \
|
||||
-o UserKnownHostsFile=/dev/null \
|
||||
-o StrictHostKeyChecking=no \
|
||||
vagrant@"$HOST_IP" 2>/dev/null
|
||||
sleep 2
|
||||
pgrep -f "$MATCH_PATTERN"
|
||||
;;
|
||||
*)
|
||||
echo "[INFO]: Delined to start a new vagrant SSH tunnel"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check for valid PRIVATE_KEY location
|
||||
PRIVATE_KEY="$(find .vagrant -name "private_key" 2>/dev/null)"
|
||||
if ! ssh-keygen -l -f "$PRIVATE_KEY" &>/dev/null; then
|
||||
echo "[ERROR]: The SSH key '$PRIVATE_KEY' is not valid. Is your virtual machine running?"
|
||||
exit 1
|
||||
fi
|
||||
echo "[CHECK]: Valid key at $PRIVATE_KEY"
|
||||
|
||||
# Grab first IP or use whatever HOST_IP_FIELD is set to and check that the guest is up
|
||||
HOST_IP="$(vagrant ssh -c "hostname -I | cut -d' ' -f${HOST_IP_FIELD:-1}" 2>/dev/null)"
|
||||
HOST_IP="${HOST_IP::-1}" # trim
|
||||
if ! ping -c 1 "$HOST_IP" &>/dev/null; then
|
||||
echo "[ERROR]: Cannot ping the host IP '$HOST_IP'"
|
||||
exit 1
|
||||
fi
|
||||
echo "[CHECK]: Host at $HOST_IP is up"
|
||||
|
||||
# Pattern for matching processes running
|
||||
MATCH_PATTERN="ssh -fNT -i ${PRIVATE_KEY}.*vagrant@"
|
||||
|
||||
# Check amount of processes that match the pattern
|
||||
if [ "$(pgrep -afc "$MATCH_PATTERN")" -eq 0 ]; then
|
||||
ssh_connect
|
||||
else
|
||||
# Processes found, so prompt to kill remaining ones then start tunnel
|
||||
printf "\n[WARNING]: Found processes running:\n"
|
||||
pgrep -fa "$MATCH_PATTERN"
|
||||
printf '\n'
|
||||
read -rp "Would you like to kill these processes? [y/N] " PKILL_ANSWER
|
||||
echo
|
||||
case "$PKILL_ANSWER" in
|
||||
[yY])
|
||||
echo "[WARNING]: Killing old vagrant SSH tunnel(s): "
|
||||
pgrep -f "$MATCH_PATTERN" | tee >(xargs kill -15)
|
||||
echo
|
||||
if [ "$(pgrep -afc "$MATCH_PATTERN")" -eq 0 ]; then
|
||||
ssh_connect
|
||||
else
|
||||
echo "[ERROR]: Unable to kill processes:"
|
||||
pgrep -f "$MATCH_PATTERN"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "[INFO]: Declined to kill existing processes"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
fi
|
@ -1,11 +0,0 @@
|
||||
- name: Install Dockerbox Server
|
||||
hosts: "{{ PLAYBOOK_HOST | default('none') }}"
|
||||
become: true
|
||||
roles:
|
||||
- base
|
||||
- docker
|
||||
- traefik
|
||||
- nextcloud
|
||||
- jenkins
|
||||
- prometheus
|
||||
- nginx
|
@ -4,11 +4,6 @@
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Install GPG
|
||||
ansible.builtin.apt:
|
||||
name: gpg
|
||||
state: present
|
||||
|
||||
- name: Manage root authorized_keys
|
||||
ansible.builtin.template:
|
||||
src: authorized_keys.j2
|
||||
|
@ -3,4 +3,4 @@ docker_compose_service: compose
|
||||
docker_compose: /usr/bin/docker-compose
|
||||
docker_repos_keys: "{{ docker_repos_path }}/.keys"
|
||||
docker_repos_keytype: rsa
|
||||
docker_repos_path: /srv/.compose_repos
|
||||
docker_repos_path: /srv/compose_repos
|
||||
|
@ -2,29 +2,3 @@
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
listen: compose_systemd
|
||||
|
||||
- name: Find which services had a docker-compose.yml updated
|
||||
set_fact:
|
||||
compose_restart_list: "{{ (compose_restart_list | default([])) + [item.item.name] }}"
|
||||
loop: "{{ compose_update.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
when: item.changed
|
||||
listen: compose_restart
|
||||
|
||||
- name: Find which services had their .env updated
|
||||
set_fact:
|
||||
compose_restart_list: "{{ (compose_restart_list | default([])) + [item.item.name] }}"
|
||||
loop: "{{ compose_env_update.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
when: item.changed
|
||||
listen: compose_restart
|
||||
|
||||
- name: Restart {{ docker_compose_service }} services
|
||||
ansible.builtin.systemd:
|
||||
state: restarted
|
||||
name: "{{ docker_compose_service }}@{{ item }}"
|
||||
loop: "{{ compose_restart_list | unique }}"
|
||||
when: compose_restart_list is defined
|
||||
listen: compose_restart
|
||||
|
@ -4,13 +4,6 @@
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Login to private registry
|
||||
community.docker.docker_login:
|
||||
registry_url: "{{ docker_login_url | default('') }}"
|
||||
username: "{{ docker_login_user }}"
|
||||
password: "{{ docker_login_pass }}"
|
||||
when: docker_login_user is defined and docker_login_pass is defined
|
||||
|
||||
- name: Create docker-compose root
|
||||
ansible.builtin.file:
|
||||
path: "{{ docker_compose_root }}"
|
||||
@ -38,7 +31,6 @@
|
||||
community.crypto.openssh_keypair:
|
||||
path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
|
||||
type: "{{ docker_repos_keytype }}"
|
||||
comment: "{{ ansible_hostname }}-deploy-key"
|
||||
mode: 0400
|
||||
state: present
|
||||
when: docker_compose_deploy is defined
|
||||
@ -47,15 +39,11 @@
|
||||
ansible.builtin.git:
|
||||
repo: "{{ item.url }}"
|
||||
dest: "{{ docker_repos_path }}/{{ item.name }}"
|
||||
version: "{{ item.version }}"
|
||||
accept_newhostkey: "{{ item.accept_newhostkey | default('false') }}"
|
||||
gpg_whitelist: "{{ item.trusted_keys | default([]) }}"
|
||||
verify_commit: "{{ true if (item.trusted_keys is defined and item.trusted_keys) else false }}"
|
||||
version: "{{ item.version | default('main') }}"
|
||||
force: true
|
||||
key_file: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
loop_control:
|
||||
label: "{{ item.url }}"
|
||||
when: docker_compose_deploy is defined
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
|
||||
- name: Create directories for docker-compose projects using the systemd service
|
||||
ansible.builtin.file:
|
||||
@ -63,32 +51,30 @@
|
||||
state: directory
|
||||
mode: 0400
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when: docker_compose_deploy is defined
|
||||
|
||||
- name: Synchronize docker-compose.yml
|
||||
ansible.posix.synchronize:
|
||||
- name: Copy docker-compose project directory
|
||||
ansible.builtin.copy:
|
||||
src: "{{ docker_repos_path }}/{{ item.name }}/"
|
||||
dest: "{{ docker_compose_root }}/{{ item.name }}/"
|
||||
remote_src: yes
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
when: docker_compose_deploy is defined and item.sync | default(false)
|
||||
|
||||
- name: Copy docker-compose.yml files to their service directories
|
||||
ansible.builtin.copy:
|
||||
src: "{{ docker_repos_path }}/{{ item.name }}/{{ item.path | default('docker-compose.yml') }}"
|
||||
dest: "{{ docker_compose_root }}/{{ item.name }}/docker-compose.yml"
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
register: compose_update
|
||||
notify: compose_restart
|
||||
remote_src: yes
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when: docker_compose_deploy is defined
|
||||
when: docker_compose_deploy is defined and not item.sync | default(false)
|
||||
|
||||
- name: Set environment variables for docker-compose projects
|
||||
ansible.builtin.template:
|
||||
src: docker-compose-env.j2
|
||||
dest: "{{ docker_compose_root }}/{{ item.name }}/.env"
|
||||
mode: 0400
|
||||
register: compose_env_update
|
||||
notify: compose_restart
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when: docker_compose_deploy is defined and item.env is defined
|
||||
|
||||
- name: Add users to docker group
|
||||
@ -111,6 +97,4 @@
|
||||
state: started
|
||||
enabled: true
|
||||
loop: "{{ docker_compose_deploy }}"
|
||||
loop_control:
|
||||
label: "{{ docker_compose_service }}@{{ item.name }}"
|
||||
when: item.enabled is defined and item.enabled is true
|
||||
|
@ -1,4 +1,5 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
{% if item.env is defined %}
|
||||
{% for kvpair in item.env.items() %}
|
||||
{{ kvpair.0 }}={{ kvpair.1 }}
|
||||
|
42
update-hosts.sh
Executable file
42
update-hosts.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
COMMENT="Project Moxie"
|
||||
DOMAIN="vm.krislamo.org"
|
||||
HOST[0]="traefik.${DOMAIN}"
|
||||
HOST[1]="cloud.${DOMAIN}"
|
||||
HOST[2]="git.${DOMAIN}"
|
||||
HOST[3]="jenkins.${DOMAIN}"
|
||||
HOST[4]="prom.${DOMAIN}"
|
||||
HOST[5]="grafana.${DOMAIN}"
|
||||
HOST[6]="nginx.${DOMAIN}"
|
||||
HOST[7]="vault.${DOMAIN}"
|
||||
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)
|
||||
|
||||
# Remove ^M from the end
|
||||
[ ${#VAGRANT_OUTPUT} -gt 1 ] && IP=${VAGRANT_OUTPUT::-1}
|
||||
|
||||
echo "Purging project addresses from /etc/hosts"
|
||||
sudo sed -i "s/# $COMMENT//g" /etc/hosts
|
||||
for address in "${HOST[@]}"; do
|
||||
sudo sed -i "/$address/d" /etc/hosts
|
||||
done
|
||||
|
||||
# Remove trailing newline
|
||||
sudo sed -i '${/^$/d}' /etc/hosts
|
||||
|
||||
if [ -n "$IP" ]; then
|
||||
echo -e "Adding new addresses...\n"
|
||||
echo -e "# $COMMENT" | sudo tee -a /etc/hosts
|
||||
for address in "${HOST[@]}"; do
|
||||
echo -e "$IP\t$address" | sudo tee -a /etc/hosts
|
||||
done
|
||||
else
|
||||
echo "Cannot find address. Is the Vagrant box running?"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user