Add --restart and --recreate

This commit is contained in:
Sam A. 2023-08-05 14:36:12 +02:00
parent ce7e6ffc5e
commit 23faf8f109
Signed by: samsapti
GPG Key ID: CBBBE7371E81C4EA
14 changed files with 56 additions and 33 deletions

View File

@ -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'")"

View File

@ -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:

View File

@ -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: ''

View File

@ -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:

View File

@ -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: ''

View File

@ -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: ''

View File

@ -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'

View File

@ -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'

View File

@ -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:

View File

@ -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'

View File

@ -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

View File

@ -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:

View File

@ -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: ''

View File

@ -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)