Add --restart and --recreate
This commit is contained in:
parent
ce7e6ffc5e
commit
23faf8f109
29
provision.sh
29
provision.sh
|
@ -13,7 +13,7 @@ usage() {
|
||||||
printf '$ %s\n' "$0 [--dry] docker_config"
|
printf '$ %s\n' "$0 [--dry] docker_config"
|
||||||
printf '$ %s\n' "$0 [--dry] users [--init]"
|
printf '$ %s\n' "$0 [--dry] users [--init]"
|
||||||
printf '$ %s\n' "$0 [--dry] reboot"
|
printf '$ %s\n' "$0 [--dry] reboot"
|
||||||
printf '$ %s\n' "$0 [--dry] services [--down] [SINGLE_SERVICE]"
|
printf '$ %s\n' "$0 [--dry] services [--down|--restart|--recreate] [SINGLE_SERVICE]"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_modules() {
|
install_modules() {
|
||||||
|
@ -57,16 +57,29 @@ case $TAG in
|
||||||
install_modules
|
install_modules
|
||||||
|
|
||||||
if [ "$1" = "--down" ]; then
|
if [ "$1" = "--down" ]; then
|
||||||
DOWN=1
|
ACTION="down"
|
||||||
|
shift
|
||||||
|
elif [ "$1" = "--restart" ]; then
|
||||||
|
ACTION="restart"
|
||||||
|
shift
|
||||||
|
elif [ "$1" = "--recreate" ]; then
|
||||||
|
ACTION="recreate"
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DOWN" ] && [ -n "$1" ]; then
|
case $1 in
|
||||||
VARS="single_service=$1"
|
--*)
|
||||||
elif [ -n "$DOWN" ] && [ -z "$1" ]; then
|
;;
|
||||||
VARS="stop=true"
|
*)
|
||||||
elif [ -n "$DOWN" ] && [ -n "$1" ]; then
|
SINGLE_SERVICE="$1" ;;
|
||||||
VARS='{"stop": true, "single_service": "'$1'"}'
|
esac
|
||||||
|
|
||||||
|
if [ -z "$ACTION" ] && [ -n "$SINGLE_SERVICE" ]; then
|
||||||
|
VARS="single_service=$SINGLE_SERVICE"
|
||||||
|
elif [ -n "$ACTION" ] && [ -z "$SINGLE_SERVICE" ]; then
|
||||||
|
VARS="$ACTION=true"
|
||||||
|
elif [ -n "$ACTION" ] && [ -n "$SINGLE_SERVICE" ]; then
|
||||||
|
VARS='{"'$ACTION'": true, "single_service": "'$SINGLE_SERVICE'"}'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
loop:
|
loop:
|
||||||
- docker.socket
|
- docker.socket
|
||||||
- docker.service
|
- docker.service
|
||||||
when: stop is undefined or not stop
|
when: down is undefined or not down
|
||||||
|
|
||||||
- name: Configure cron job to prune unused Docker data weekly
|
- name: Configure cron job to prune unused Docker data weekly
|
||||||
ansible.builtin.cron:
|
ansible.builtin.cron:
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
- name: Deploy Caddy Docker container
|
- name: Deploy Caddy Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: caddy
|
name: caddy
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
recreate: "{{ dockerfile.changed }}"
|
recreate: "{{ dockerfile.changed or (recreate is defined and recreate) }}"
|
||||||
image: custom/caddy:{{ services.caddy.version }}-alpine
|
image: custom/caddy:{{ services.caddy.version }}-alpine
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -16,8 +16,9 @@
|
||||||
- name: Deploy Emby Docker container
|
- name: Deploy Emby Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: emby
|
name: emby
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: emby/embyserver_arm64v8:{{ services.emby.version }}
|
image: emby/embyserver_arm64v8:{{ services.emby.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -22,8 +22,9 @@
|
||||||
- name: Deploy IPFS Kubo Docker container
|
- name: Deploy IPFS Kubo Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: ipfs_kubo
|
name: ipfs_kubo
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: ipfs/kubo:{{ services.ipfs.version }}
|
image: ipfs/kubo:{{ services.ipfs.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
- name: Deploy Monero node Docker container
|
- name: Deploy Monero node Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: monerod
|
name: monerod
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: sethsimmons/simple-monerod:{{ services.monerod.version }}
|
image: sethsimmons/simple-monerod:{{ services.monerod.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -37,8 +37,9 @@
|
||||||
- name: Deploy Nextcloud with Docker Compose
|
- name: Deploy Nextcloud with Docker Compose
|
||||||
community.docker.docker_compose:
|
community.docker.docker_compose:
|
||||||
project_name: nextcloud
|
project_name: nextcloud
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'present' }}"
|
state: "{{ 'absent' if down is defined and down else 'present' }}"
|
||||||
restarted: "{{ stop is undefined or not stop }}"
|
restarted: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ 'always' if recreate is defined and recreate else 'smart' }}"
|
||||||
pull: true
|
pull: true
|
||||||
definition:
|
definition:
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
|
@ -37,8 +37,9 @@
|
||||||
- name: Deploy Pi-hole with Docker Compose
|
- name: Deploy Pi-hole with Docker Compose
|
||||||
community.docker.docker_compose:
|
community.docker.docker_compose:
|
||||||
project_name: pihole
|
project_name: pihole
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'present' }}"
|
state: "{{ 'absent' if down is defined and down else 'present' }}"
|
||||||
restarted: "{{ stop is undefined or not stop }}"
|
restarted: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ 'always' if recreate is defined and recreate else 'smart' }}"
|
||||||
pull: true
|
pull: true
|
||||||
definition:
|
definition:
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
|
@ -15,8 +15,9 @@
|
||||||
- name: Deploy Postfix Docker container
|
- name: Deploy Postfix Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: postfix
|
name: postfix
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: boky/postfix:{{ services.postfix.version }}
|
image: boky/postfix:{{ services.postfix.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
- name: Deploy Restic with Docker Compose
|
- name: Deploy Restic with Docker Compose
|
||||||
community.docker.docker_compose:
|
community.docker.docker_compose:
|
||||||
project_name: restic
|
project_name: restic
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'present' }}"
|
state: "{{ 'absent' if down is defined and down else 'present' }}"
|
||||||
restarted: "{{ stop is undefined or not stop }}"
|
restarted: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ 'always' if recreate is defined and recreate else 'smart' }}"
|
||||||
pull: true
|
pull: true
|
||||||
definition:
|
definition:
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
- name: Deploy snowflake-proxy Docker container
|
- name: Deploy snowflake-proxy Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: snowflake-proxy
|
name: snowflake-proxy
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: thetorproject/snowflake-proxy:{{ services.snowflake.version }}
|
image: thetorproject/snowflake-proxy:{{ services.snowflake.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
network_mode: host
|
network_mode: host
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
- name: Deploy Watchtower Docker container
|
- name: Deploy Watchtower Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: watchtower
|
name: watchtower
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: containrrr/watchtower:{{ services.watchtower.version }}
|
image: containrrr/watchtower:{{ services.watchtower.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
networks:
|
networks:
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
- name: Deploy Wireguard Docker container
|
- name: Deploy Wireguard Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: wireguard
|
name: wireguard
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: linuxserver/wireguard:{{ services.wireguard.version }}
|
image: linuxserver/wireguard:{{ services.wireguard.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
apply:
|
apply:
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
vars:
|
vars:
|
||||||
stop: true
|
down: true
|
||||||
when: needs_reboot.stat.exists or
|
when: needs_reboot.stat.exists or
|
||||||
(do_reboot is defined and do_reboot)
|
(do_reboot is defined and do_reboot)
|
||||||
|
|
||||||
|
|
Reference in a new issue