-
Notifications
You must be signed in to change notification settings - Fork 30
/
pihole_sync.j2
31 lines (26 loc) · 1.47 KB
/
pihole_sync.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
DOCKER_RESTART=0
if [[ $(ip a | grep {{ pihole_vip_ipv4.split('/')[0] }}) ]]; then
RSYNC_GRAVITY=$(rsync -a --info=name -e "ssh -i {{ ssh_key.filename }}" {{ ansible_user_dir }}/pihole/pihole/gravity.db {{ ansible_user }}@{{ sync_target }}:{{ ansible_user_dir }})
if [ $? -eq 0 ]; then
if [ -n "$RSYNC_GRAVITY" ]; then
ssh -i {{ ssh_key.filename }} {{ ansible_user }}@{{ sync_target }} cp {{ ansible_user_dir }}/gravity.db {{ ansible_user_dir }}/pihole/pihole
DOCKER_RESTART=1
fi
fi
RSYNC_DNS=$(rsync -a --info=name -e "ssh -i {{ ssh_key.filename }}" {{ ansible_user_dir }}/pihole/pihole/custom.list {{ ansible_user }}@{{ sync_target }}:{{ ansible_user_dir }})
if [ $? -eq 0 ]; then
if [ -n "$RSYNC_DNS" ]; then
ssh -i {{ ssh_key.filename }} {{ ansible_user }}@{{ sync_target }} sudo cp {{ ansible_user_dir }}/custom.list {{ ansible_user_dir }}/pihole/pihole
fi
fi
RSYNC_CNAME=$(rsync -a --info=name -e "ssh -i {{ ssh_key.filename }}" {{ ansible_user_dir }}/pihole/dnsmasq.d/05-pihole-custom-cname.conf {{ ansible_user }}@{{ sync_target }}:{{ ansible_user_dir }})
if [ $? -eq 0 ]; then
if [ -n "$RSYNC_CNAME" ]; then
ssh -i {{ ssh_key.filename }} {{ ansible_user }}@{{ sync_target }} sudo cp {{ ansible_user_dir }}/05-pihole-custom-cname.conf {{ ansible_user_dir }}/pihole/dnsmasq.d
fi
fi
if [ $DOCKER_RESTART -eq 1 ]; then
ssh -i {{ ssh_key.filename }} {{ ansible_user }}@{{ sync_target }} docker restart pihole
fi
fi