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