Compare commits
4 Commits
d5bad0b1cc
...
28806de6e4
Author | SHA1 | Date | |
---|---|---|---|
28806de6e4 | |||
01e8e22c01 | |||
a31bf233dc | |||
60fafed9cd |
@ -5,9 +5,11 @@
|
|||||||
- host_vars/dockerbox.yml
|
- host_vars/dockerbox.yml
|
||||||
roles:
|
roles:
|
||||||
- base
|
- base
|
||||||
|
- proxy
|
||||||
- docker
|
- docker
|
||||||
|
- mariadb
|
||||||
- traefik
|
- traefik
|
||||||
- nextcloud
|
- nextcloud
|
||||||
- jenkins
|
# - jenkins
|
||||||
- prometheus
|
# - prometheus
|
||||||
- nginx
|
# - nginx
|
||||||
|
@ -2,29 +2,60 @@
|
|||||||
allow_reboot: false
|
allow_reboot: false
|
||||||
manage_network: false
|
manage_network: false
|
||||||
|
|
||||||
|
# Import my GPG key for git signature verification
|
||||||
|
root_gpgkeys:
|
||||||
|
- name: kris@lamoureux.io
|
||||||
|
id: FBF673CEEC030F8AECA814E73EDA9C3441EDA925
|
||||||
|
|
||||||
|
# proxy
|
||||||
|
proxy:
|
||||||
|
servers:
|
||||||
|
- domain: cloud.local.krislamo.org
|
||||||
|
proxy_pass: http://127.0.0.1:8000
|
||||||
|
|
||||||
# docker
|
# docker
|
||||||
|
docker_official: true # docker's apt repos
|
||||||
docker_users:
|
docker_users:
|
||||||
- vagrant
|
- vagrant
|
||||||
|
|
||||||
|
docker_compose_env_nolog: false # dev only setting
|
||||||
|
docker_compose_deploy:
|
||||||
|
# Traefik
|
||||||
|
- name: traefik
|
||||||
|
url: https://github.com/krislamo/traefik
|
||||||
|
version: e03268af4cf942c47cba66c2112628dbcad1b756
|
||||||
|
path: docker-compose.web.yml
|
||||||
|
enabled: true
|
||||||
|
accept_newhostkey: true
|
||||||
|
trusted_keys:
|
||||||
|
- FBF673CEEC030F8AECA814E73EDA9C3441EDA925
|
||||||
|
env:
|
||||||
|
ENABLE: true
|
||||||
|
# Nextcloud
|
||||||
|
- name: nextcloud
|
||||||
|
url: https://git.krislamo.org/kris/nextcloud
|
||||||
|
version: a2e38cec703839211e11dc8347b4cdd62fa6f24d
|
||||||
|
env:
|
||||||
|
DATA: ./data
|
||||||
|
|
||||||
# traefik
|
# traefik
|
||||||
traefik_version: latest
|
traefik:
|
||||||
traefik_dashboard: true
|
ENABLE: true
|
||||||
traefik_domain: traefik.local.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
|
|
||||||
|
|
||||||
# nextcloud
|
# nextcloud
|
||||||
nextcloud_version: stable
|
nextcloud:
|
||||||
nextcloud_admin: admin
|
DB_NAME: nextcloud
|
||||||
nextcloud_pass: password
|
DB_USER: nextcloud
|
||||||
nextcloud_domain: cloud.local.krislamo.org
|
DB_PASSWD: password
|
||||||
|
|
||||||
nextcloud_dbversion: latest
|
# nextcloud
|
||||||
nextcloud_dbpass: password
|
#nextcloud_version: stable
|
||||||
|
#nextcloud_admin: admin
|
||||||
|
#nextcloud_pass: password
|
||||||
|
#nextcloud_domain: cloud.local.krislamo.org
|
||||||
|
|
||||||
|
#nextcloud_dbversion: latest
|
||||||
|
#nextcloud_dbpass: password
|
||||||
|
|
||||||
# jenkins
|
# jenkins
|
||||||
jenkins_version: lts
|
jenkins_version: lts
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
# Root check
|
# Root check
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "[ERROR]: Please run script as root"
|
echo "[ERROR]: Please run this script as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -41,8 +41,8 @@ function ssh_connect {
|
|||||||
printf "[INFO]: Starting new vagrant SSH tunnel on PID "
|
printf "[INFO]: Starting new vagrant SSH tunnel on PID "
|
||||||
sudo -u "$USER" ssh -fNT -i "$PRIVATE_KEY" \
|
sudo -u "$USER" ssh -fNT -i "$PRIVATE_KEY" \
|
||||||
-L 22:localhost:22 \
|
-L 22:localhost:22 \
|
||||||
-L 80:localhost:80 \
|
-L 80:"$HOST_IP":80 \
|
||||||
-L 443:localhost:443 \
|
-L 443:"$HOST_IP":443 \
|
||||||
-L 8443:localhost:8443 \
|
-L 8443:localhost:8443 \
|
||||||
-o UserKnownHostsFile=/dev/null \
|
-o UserKnownHostsFile=/dev/null \
|
||||||
-o StrictHostKeyChecking=no \
|
-o StrictHostKeyChecking=no \
|
||||||
@ -51,7 +51,7 @@ function ssh_connect {
|
|||||||
pgrep -f "$MATCH_PATTERN"
|
pgrep -f "$MATCH_PATTERN"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "[INFO]: Delined to start a new vagrant SSH tunnel"
|
echo "[INFO]: Declined to start a new vagrant SSH tunnel"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -64,7 +64,7 @@ PRIVATE_KEY="$(find .vagrant -name "private_key" 2>/dev/null | sort)"
|
|||||||
if [ "$(echo "$PRIVATE_KEY" | wc -l)" -gt 1 ]; then
|
if [ "$(echo "$PRIVATE_KEY" | wc -l)" -gt 1 ]; then
|
||||||
while IFS= read -r KEYFILE; do
|
while IFS= read -r KEYFILE; do
|
||||||
if ! ssh-keygen -l -f "$KEYFILE" &>/dev/null; then
|
if ! ssh-keygen -l -f "$KEYFILE" &>/dev/null; then
|
||||||
echo "[ERROR]: The SSH key '$KEYFILE' is not valid. Is your virtual machines running?"
|
echo "[ERROR]: The SSH key '$KEYFILE' is not valid. Are your virtual machines running?"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "[CHECK]: Valid key at $KEYFILE"
|
echo "[CHECK]: Valid key at $KEYFILE"
|
||||||
@ -78,7 +78,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Grab first IP or use whatever HOST_IP_FIELD is set to and check that the guest is up
|
# 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}" "${1:-default}" 2>/dev/null)"
|
HOST_IP="$(sudo -u "$SUDO_USER" vagrant ssh -c "hostname -I | cut -d' ' -f${HOST_IP_FIELD:-1}" "${1:-default}" 2>/dev/null)"
|
||||||
if [ -z "$HOST_IP" ]; then
|
if [ -z "$HOST_IP" ]; then
|
||||||
echo "[ERROR]: Failed to find ${1:-default}'s IP"
|
echo "[ERROR]: Failed to find ${1:-default}'s IP"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -1,11 +1 @@
|
|||||||
# container names
|
nextcloud_name: nextcloud
|
||||||
nextcloud_container: nextcloud
|
|
||||||
nextcloud_dbcontainer: "{{ nextcloud_container }}-db"
|
|
||||||
|
|
||||||
# database settings
|
|
||||||
nextcloud_dbname: "{{ nextcloud_container }}"
|
|
||||||
nextcloud_dbuser: "{{ nextcloud_dbname }}"
|
|
||||||
|
|
||||||
# host mounts
|
|
||||||
nextcloud_root: "/opt/{{ nextcloud_container }}/public_html"
|
|
||||||
nextcloud_dbroot: "/opt/{{ nextcloud_container }}/database"
|
|
||||||
|
@ -1,76 +1,54 @@
|
|||||||
- name: Create Nextcloud network
|
- name: Install MySQL module for Ansible
|
||||||
community.general.docker_network:
|
ansible.builtin.apt:
|
||||||
name: "{{ nextcloud_container }}"
|
name: python3-pymysql
|
||||||
|
state: present
|
||||||
|
|
||||||
- name: Start Nextcloud's database container
|
- name: Create Nextcloud database
|
||||||
community.general.docker_container:
|
community.mysql.mysql_db:
|
||||||
name: "{{ nextcloud_dbcontainer }}"
|
name: "{{ nextcloud.DB_NAME }}"
|
||||||
image: mariadb:{{ nextcloud_dbversion }}
|
state: present
|
||||||
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
||||||
|
|
||||||
|
- name: Create Nextcloud database user
|
||||||
|
community.mysql.mysql_user:
|
||||||
|
name: "{{ nextcloud.DB_USER }}"
|
||||||
|
password: "{{ nextcloud.DB_PASSWD }}"
|
||||||
|
host: '%'
|
||||||
|
state: present
|
||||||
|
priv: "{{ nextcloud.DB_NAME }}.*:ALL"
|
||||||
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
||||||
|
|
||||||
|
- name: Start Nextcloud service and enable on boot
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: "{{ docker_compose_service }}@{{ nextcloud_name }}"
|
||||||
state: started
|
state: started
|
||||||
restart_policy: always
|
enabled: true
|
||||||
volumes: "{{ nextcloud_dbroot }}:/var/lib/mysql"
|
when: nextcloud.ENABLE | default('false')
|
||||||
networks_cli_compatible: true
|
|
||||||
networks:
|
|
||||||
- name: "{{ nextcloud_container }}"
|
|
||||||
env:
|
|
||||||
MYSQL_RANDOM_ROOT_PASSWORD: "true"
|
|
||||||
MYSQL_DATABASE: "{{ nextcloud_dbname }}"
|
|
||||||
MYSQL_USER: "{{ nextcloud_dbuser }}"
|
|
||||||
MYSQL_PASSWORD: "{{ nextcloud_dbpass }}"
|
|
||||||
|
|
||||||
- name: Start Nextcloud container
|
|
||||||
community.general.docker_container:
|
|
||||||
name: "{{ nextcloud_container }}"
|
|
||||||
image: nextcloud:{{ nextcloud_version }}
|
|
||||||
state: started
|
|
||||||
restart_policy: always
|
|
||||||
volumes: "{{ nextcloud_root }}:/var/www/html"
|
|
||||||
networks_cli_compatible: true
|
|
||||||
networks:
|
|
||||||
- name: "{{ nextcloud_container }}"
|
|
||||||
- name: traefik
|
|
||||||
env:
|
|
||||||
PHP_MEMORY_LIMIT: 1024M
|
|
||||||
labels:
|
|
||||||
traefik.http.routers.nextcloud.rule: "Host(`{{ nextcloud_domain }}`)"
|
|
||||||
traefik.http.routers.nextcloud.entrypoints: websecure
|
|
||||||
traefik.http.routers.nextcloud.tls.certresolver: letsencrypt
|
|
||||||
traefik.http.routers.nextcloud.middlewares: "securehttps@file,nextcloud-webdav"
|
|
||||||
traefik.http.middlewares.nextcloud-webdav.redirectregex.regex: "https://(.*)/.well-known/(card|cal)dav"
|
|
||||||
traefik.http.middlewares.nextcloud-webdav.redirectregex.replacement: "https://${1}/remote.php/dav/"
|
|
||||||
traefik.http.middlewares.nextcloud-webdav.redirectregex.permanent: "true"
|
|
||||||
traefik.docker.network: traefik
|
|
||||||
traefik.enable: "true"
|
|
||||||
|
|
||||||
- name: Grab Nextcloud database container information
|
|
||||||
community.general.docker_container_info:
|
|
||||||
name: "{{ nextcloud_dbcontainer }}"
|
|
||||||
register: nextcloud_dbinfo
|
|
||||||
|
|
||||||
- name: Grab Nextcloud container information
|
- name: Grab Nextcloud container information
|
||||||
community.general.docker_container_info:
|
community.general.docker_container_info:
|
||||||
name: "{{ nextcloud_container }}"
|
name: "{{ nextcloud_name }}"
|
||||||
register: nextcloud_info
|
register: nextcloud_info
|
||||||
|
|
||||||
- name: Wait for Nextcloud to become available
|
- name: Wait for Nextcloud to become available
|
||||||
ansible.builtin.wait_for:
|
ansible.builtin.wait_for:
|
||||||
host: "{{ nextcloud_info.container.NetworkSettings.Networks.traefik.IPAddress }}"
|
#debug:
|
||||||
|
#host: "{{ nextcloud_info.container.NetworkSettings.Networks.traefik.IPAddress }}"
|
||||||
|
#var: nextcloud_info.container.NetworkSettings
|
||||||
port: 80
|
port: 80
|
||||||
|
|
||||||
- name: Check Nextcloud status
|
- name: Check Nextcloud status
|
||||||
ansible.builtin.command: "docker exec --user www-data {{ nextcloud_container }}
|
ansible.builtin.command: "docker exec --user www-data {{ nextcloud_name }}
|
||||||
php occ status"
|
php occ status"
|
||||||
register: nextcloud_status
|
register: nextcloud_status
|
||||||
args:
|
changed_when: false
|
||||||
removes: "{{ nextcloud_root }}/config/CAN_INSTALL"
|
|
||||||
|
|
||||||
- name: Wait for Nextcloud database to become available
|
- name: Check status return
|
||||||
ansible.builtin.wait_for:
|
debug:
|
||||||
host: "{{ nextcloud_dbinfo.container.NetworkSettings.Networks.nextcloud.IPAddress }}"
|
var: nextcloud_status.stderr[:26]
|
||||||
port: 3306
|
|
||||||
|
|
||||||
- name: Install Nextcloud
|
- name: Install Nextcloud
|
||||||
ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_container }}
|
ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_name }}
|
||||||
php occ maintenance:install
|
php occ maintenance:install
|
||||||
--database "mysql"
|
--database "mysql"
|
||||||
--database-host "{{ nextcloud_dbcontainer }}"
|
--database-host "{{ nextcloud_dbcontainer }}"
|
||||||
@ -80,9 +58,7 @@
|
|||||||
--admin-user "{{ nextcloud_admin }}"
|
--admin-user "{{ nextcloud_admin }}"
|
||||||
--admin-pass "{{ nextcloud_pass }}"'
|
--admin-pass "{{ nextcloud_pass }}"'
|
||||||
register: nextcloud_install
|
register: nextcloud_install
|
||||||
when:
|
when: nextcloud_status.stderr[:26] == "Nextcloud is not installed"
|
||||||
- nextcloud_status.stdout[:26] == "Nextcloud is not installed"
|
|
||||||
- nextcloud_domain is defined
|
|
||||||
|
|
||||||
- name: Set Nextcloud's Trusted Proxy
|
- name: Set Nextcloud's Trusted Proxy
|
||||||
ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_container }}
|
ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_container }}
|
||||||
|
@ -21,20 +21,6 @@
|
|||||||
loop: "{{ traefik_external }}"
|
loop: "{{ traefik_external }}"
|
||||||
when: traefik_external is defined
|
when: traefik_external is defined
|
||||||
|
|
||||||
- name: Install Traefik's docker-compose file
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: docker-compose.yml.j2
|
|
||||||
dest: "{{ traefik_root }}/docker-compose.yml"
|
|
||||||
mode: 0400
|
|
||||||
notify: restart_traefik
|
|
||||||
|
|
||||||
- name: Install Traefik's docker-compose variables
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: compose-env.j2
|
|
||||||
dest: "{{ traefik_root }}/.env"
|
|
||||||
mode: 0400
|
|
||||||
notify: restart_traefik
|
|
||||||
|
|
||||||
- name: Install static Traefik configuration
|
- name: Install static Traefik configuration
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: traefik.yml.j2
|
src: traefik.yml.j2
|
||||||
@ -42,8 +28,9 @@
|
|||||||
mode: 0400
|
mode: 0400
|
||||||
notify: restart_traefik
|
notify: restart_traefik
|
||||||
|
|
||||||
- name: Start and enable Traefik service
|
- name: Start Traefik service and enable on boot
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: "{{ docker_compose_service }}@{{ traefik_name }}"
|
name: "{{ docker_compose_service }}@{{ traefik_name }}"
|
||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: true
|
||||||
|
when: traefik.ENABLED | default('false')
|
||||||
|
Loading…
Reference in New Issue
Block a user