Add DDNS service to the Pi
This commit is contained in:
parent
04c8038733
commit
04671f7d31
10 changed files with 96 additions and 12 deletions
10
roles/cloudflare-ddns/files/cloudflare_ddns.timer
Normal file
10
roles/cloudflare-ddns/files/cloudflare_ddns.timer
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Cloudflare DDNS timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
RandomizedDelaySec=900
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
|
|
@ -40,8 +40,8 @@ for subdomain in subdomains:
|
|||
|
||||
resolvedIP = resolve_name(fullDomainName)
|
||||
if resolvedIP == publicIP:
|
||||
logging.info(f'Currently resolved name already matches the public ip ({publicIP}), exiting...')
|
||||
exit(0)
|
||||
logging.info(f'Currently resolved name already matches the public ip ({publicIP}), skipping this name...')
|
||||
continue
|
||||
|
||||
zoneId = cloudflare.get_zone_id(fixedTopLevelDomain)
|
||||
recordId = cloudflare.get_record_id(zoneId, fullDomainName)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/bash
|
||||
source ~/bin/cloudflare_ddns/venv/bin/activate
|
||||
python3 ~/bin/cloudflare_ddns/cloudflare_ddns.py --config-file ~/cloudflare_ddns/ddns_config.ini $@
|
||||
|
|
@ -7,3 +7,60 @@
|
|||
vars:
|
||||
username: cloudflare_ddns
|
||||
password: "{{ cloudflare_ddns_user_password }}"
|
||||
- name: Install Python dependencies # noqa: package-latest
|
||||
become: true
|
||||
ansible.builtin.apt:
|
||||
pkg: python3-pip
|
||||
state: latest
|
||||
- name: Copy over DDNS scripting
|
||||
become: true
|
||||
become_user: cloudflare_ddns
|
||||
ansible.builtin.copy:
|
||||
src: cloudflare_ddns
|
||||
dest: ~/bin/
|
||||
mode: '0700'
|
||||
- name: Configure Python venv
|
||||
become: true
|
||||
become_user: cloudflare_ddns
|
||||
ansible.builtin.shell: |
|
||||
cd ~/bin/cloudflare_ddns
|
||||
python3 -m venv ./venv
|
||||
chmod u+x ./venv/bin/activate
|
||||
source ./venv/bin/activate
|
||||
pip3 install -r ./requirements.txt
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: ~/bin/cloudflare_ddns/venv
|
||||
- name: Create directory for storing public IP change logs and config
|
||||
become: true
|
||||
become_user: cloudflare_ddns
|
||||
ansible.builtin.file:
|
||||
path: ~/cloudflare_ddns
|
||||
state: directory
|
||||
mode: '0700'
|
||||
- name: Fill config file and store it in folder
|
||||
become: true
|
||||
become_user: cloudflare_ddns
|
||||
ansible.builtin.template:
|
||||
src: ddns_config.ini.j2
|
||||
dest: ~/cloudflare_ddns/ddns_config.ini
|
||||
mode: '0600'
|
||||
- name: Install Cloudflare DDNS service file
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: cloudflare_ddns.service
|
||||
dest: /lib/systemd/system/
|
||||
mode: '0644'
|
||||
- name: Install Cloudflare DDNS timer file
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
src: cloudflare_ddns.timer
|
||||
dest: /lib/systemd/system/
|
||||
mode: '0644'
|
||||
- name: Enable the newly added systemd timer
|
||||
become: true
|
||||
ansible.builtin.systemd_service:
|
||||
daemon_reload: true
|
||||
name: cloudflare_ddns.timer
|
||||
state: started
|
||||
enabled: true
|
||||
|
|
|
|||
13
roles/cloudflare-ddns/templates/cloudflare_ddns.service
Normal file
13
roles/cloudflare-ddns/templates/cloudflare_ddns.service
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[Unit]
|
||||
Description=Cloudflare DDNS service
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=cloudflare_ddns
|
||||
Group=cloudflare_ddns
|
||||
ExecStart=/home/cloudflare_ddns/bin/cloudflare_ddns/cloudflare_ddns.sh {{ wireguard_address }}
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
|
|
@ -2,5 +2,4 @@
|
|||
dns_cloudflare_token = {{ dns_cloudflare_token }}
|
||||
|
||||
[log_changes]
|
||||
# TODO: Update this...
|
||||
log_path = /home/thomas/repositories/raspberry-pi-iac/ddns_update.log
|
||||
log_path = /home/cloudflare_ddns/cloudflare_ddns/ddns_update.log
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
$ANSIBLE_VAULT;1.1;AES256
|
||||
66356265626336393935313366363030306565343830633365383938383363376430326330633430
|
||||
6138653236396139613861393639303766633062323336310a373133336139316661383039303533
|
||||
63343563333232633166353061346630326339303062663066663464333733613164623864306264
|
||||
6165366331373734660a623664353734613037343537646135663239616239383136636562356137
|
||||
62646565626565663831396137313364626632353064633661333135636439663537343438653237
|
||||
66633733353435653031366533376463616335633131613862393764353337643665353464623939
|
||||
33613931343561316133386636613036666363663161353163306566393234323239643762386130
|
||||
35623434313161313034
|
||||
66636366666633653933313233613230396161303661363939646564633533363963623639633662
|
||||
3266613932346433326263313864336437656132643534660a386639623636656161376237333735
|
||||
32613536383532396632343235323338626562393138396266393765373735666661646534333230
|
||||
3366633633393866620a643161323663316135303235376263633664333665383535386162356330
|
||||
35656339306365373366333338643433613637393431353336353965663030366330386231653562
|
||||
38663362356430373161373330663333636363653866643633613631333733356236636635306163
|
||||
64326137643965623761303730613066366334313734333032653461303064373162303838643233
|
||||
65643031316465326263643438326235313537636330323735353664613337653730313264376234
|
||||
35353134626236306632386462393563303433323738336231303863366463386433373733333532
|
||||
6134386564383632663264343032323566323662313331663530
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue