mirror of
https://gitea.0xace.cc/ansible-galaxy/ddclient.git
synced 2024-11-24 15:56:40 +00:00
first commit
This commit is contained in:
commit
d5dffb2ad0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.galaxy_install_info
|
32
defaults/main.yml
Normal file
32
defaults/main.yml
Normal file
@ -0,0 +1,32 @@
|
||||
ddclient_containerized: false
|
||||
ddclient_container_engine: "{{ container_engine | default('podman') }}"
|
||||
ddclient_network_mode: "host"
|
||||
ddclient_namespace: "{{ namespace | default('ddclient') }}"
|
||||
ddclient_container_name: "{{ ddclient_namespace }}-ddclient"
|
||||
ddclient_container_registry: "{{ container_registry | default(docker_registry) | default('registry.geekhome.org/ghp') }}"
|
||||
ddclient_image_name: "ddclient"
|
||||
ddclient_image_tag: "v3.9.1-ls45"
|
||||
ddclient_systemd_unit_name: "{{ ddclient_container_name }}-container.service"
|
||||
|
||||
# Volumes for containers
|
||||
ddclient_default_volumes:
|
||||
'/opt/{{ ddclient_namespace }}/ddclient.conf': /config/ddclient.conf
|
||||
'/opt/{{ ddclient_namespace }}/Kvps.key': /config/Kvps.key
|
||||
'/opt/{{ ddclient_namespace }}/Kvps.private': /config/Kvps.private
|
||||
|
||||
# Put tsig key in files directory
|
||||
ddclient_tsig_public_key_file: []
|
||||
ddclient_tsig_private_key_file: []
|
||||
|
||||
# OR define with base64 vars
|
||||
ddclient_tsig_public_key_base64: []
|
||||
ddclient_tsig_private_key_base64: []
|
||||
|
||||
# Override default ddclient.conf template
|
||||
ddclient_conf_override: []
|
||||
|
||||
ddclient_hosts: {}
|
||||
# - name: my-record.example.com
|
||||
# dns_ip: 1.2.3.4
|
||||
# domain: example.com
|
||||
|
39
handlers/main.yml
Normal file
39
handlers/main.yml
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
- name: Start ddclient
|
||||
systemd:
|
||||
name: ddclient
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Restart ddclient
|
||||
systemd:
|
||||
name: ddclient
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Restart docker ddclient
|
||||
community.general.docker_container:
|
||||
name: "{{ ddclient_container_name }}"
|
||||
image: "{{ ddclient_container_registry }}/{{ ddclient_image_name }}:{{ ddclient_image_tag }}"
|
||||
network_mode: "{{ ddclient_network_mode }}"
|
||||
state: started
|
||||
restart: yes
|
||||
container_default_behavior: no_defaults
|
||||
detach: true
|
||||
restart_policy: unless-stopped
|
||||
volumes: "{{ ddclient_volumes }}"
|
||||
when: ddclient_container_engine == 'docker'
|
||||
|
||||
- name: Restart podman ddclient
|
||||
containers.podman.podman_container:
|
||||
name: "{{ ddclient_container_name }}"
|
||||
hostname: "{{ ddclient_container_name }}"
|
||||
network: "{{ ddclient_network_mode }}"
|
||||
image: "{{ ddclient_container_registry }}/{{ ddclient_image_name }}:{{ ddclient_image_tag }}"
|
||||
state: started
|
||||
restart: yes
|
||||
volumes: "{{ ddclient_volumes }}"
|
||||
when: ddclient_container_engine == 'podman'
|
||||
|
40
tasks/configure.yml
Normal file
40
tasks/configure.yml
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
- block:
|
||||
- name: Create public key for ddclient from file
|
||||
copy:
|
||||
src: "{{ ddclient_tsig_public_key }}"
|
||||
dest: /etc/Kvps.key
|
||||
when: ddclient_tsig_public_key_file | length > 0
|
||||
|
||||
- name: Create private key for ddclient from file
|
||||
copy:
|
||||
src: "{{ ddclient_tsig_private_key }}"
|
||||
dest: /etc/Kvps.private
|
||||
when: ddclient_tsig_private_key_file | length > 0
|
||||
|
||||
- name: Create public key for ddclient from var
|
||||
copy:
|
||||
content: "{{ ddclient_tsig_public_key_base64 | b64decode }}"
|
||||
dest: /etc/Kvps.key
|
||||
when: ddclient_tsig_public_key_base64 | length > 0
|
||||
|
||||
- name: Create private key for ddclient from var
|
||||
copy:
|
||||
content: "{{ ddclient_tsig_private_key_base64 | b64decode }}"
|
||||
dest: /etc/Kvps.private
|
||||
when: ddclient_tsig_private_key_base64 | length > 0
|
||||
|
||||
- name: Configure ddlient.conf with template
|
||||
template:
|
||||
src: "ddclient.conf.j2"
|
||||
dest: "/etc/ddclient.conf"
|
||||
when: ddclient_conf_override | length == 0
|
||||
notify: Restart ddclient
|
||||
|
||||
- name: Configure ddlient.conf with overriding from var
|
||||
copy:
|
||||
content: "{{ ddclient_conf_override }}"
|
||||
dest: "/etc/ddclient.conf"
|
||||
when: ddclient_conf_override | length > 0
|
||||
notify: Restart ddclient
|
||||
|
33
tasks/docker.yml
Normal file
33
tasks/docker.yml
Normal file
@ -0,0 +1,33 @@
|
||||
---
|
||||
- name: Create configuration dir for {{ ddclient_namespace }}
|
||||
file:
|
||||
name: "/opt/{{ ddclient_namespace }}"
|
||||
state: directory
|
||||
|
||||
- name: Copy ddclient configuration for {{ ddclient_namespace }}
|
||||
copy:
|
||||
dest: "/opt/{{ ddclient_namespace }}/ddclient.conf"
|
||||
content: "{{ ddclient_conf }}"
|
||||
notify: Restart docker ddclient
|
||||
|
||||
- name: Copy Kvps.key for {{ ddclient_namespace }}
|
||||
copy:
|
||||
dest: "/opt/{{ ddclient_namespace }}/Kvps.key"
|
||||
content: "{{ ddclient_tsig_public_key_base64 | b64decode }}"
|
||||
notify: Restart docker ddclient
|
||||
|
||||
- name: Copy Kvps.private for {{ ddclient_namespace }}
|
||||
copy:
|
||||
dest: "/opt/{{ ddclient_namespace }}/Kvps.private"
|
||||
content: "{{ ddclient_tsig_private_key_base64 | b64decode }}"
|
||||
notify: Restart docker ddclient
|
||||
|
||||
- name: Start ddclient in docker for {{ ddclient_namespace }}
|
||||
docker_container:
|
||||
name: "{{ ddclient_container_name }}"
|
||||
image: "{{ ddclient_container_registry }}/{{ ddclient_image_name }}:{{ ddclient_image_tag }}"
|
||||
network_mode: "{{ ddclient_network_mode }}"
|
||||
state: started
|
||||
container_default_behavior: no_defaults
|
||||
restart_policy: unless-stopped
|
||||
volumes: "{{ ddclient_volumes }}"
|
12
tasks/install.yml
Normal file
12
tasks/install.yml
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
- block:
|
||||
- name: Install ddclient and bind-utils
|
||||
dnf:
|
||||
name:
|
||||
- ddclient
|
||||
- bind-utils
|
||||
state: present
|
||||
notify: Start ddclient
|
||||
register: install_ddlient_result
|
||||
tags:
|
||||
- ddclient-install
|
22
tasks/main.yml
Normal file
22
tasks/main.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: Install ddclient (not containerized)
|
||||
when: not ddclient_containerized
|
||||
block:
|
||||
- import_tasks: install.yml
|
||||
- import_tasks: configure.yml
|
||||
become: true
|
||||
|
||||
- name: Install ddclient (containerized)
|
||||
when: ddclient_containerized
|
||||
block:
|
||||
- name: Merge volumes
|
||||
set_fact:
|
||||
ddclient_volumes: "{{ ddclient_volumes | default([]) + [item.key +':'+ item.value] }}"
|
||||
loop: "{{ ddclient_default_volumes | dict2items }}"
|
||||
|
||||
- import_tasks: docker.yml
|
||||
when: ddclient_container_engine == "docker"
|
||||
|
||||
- import_tasks: podman.yml
|
||||
when: ddclient_container_engine == "podman"
|
||||
become: true
|
49
tasks/podman.yml
Normal file
49
tasks/podman.yml
Normal file
@ -0,0 +1,49 @@
|
||||
---
|
||||
- name: Create configuration dir for {{ ddclient_namespace }}
|
||||
file:
|
||||
name: "/opt/{{ ddclient_namespace }}"
|
||||
state: directory
|
||||
|
||||
- name: Copy ddclient configuration for {{ ddclient_namespace }}
|
||||
copy:
|
||||
dest: "/opt/{{ ddclient_namespace }}/ddclient.conf"
|
||||
content: "{{ ddclient_conf }}"
|
||||
notify: Restart podman ddclient
|
||||
|
||||
- name: Copy Kvps.key for {{ ddclient_namespace }}
|
||||
copy:
|
||||
dest: "/opt/{{ ddclient_namespace }}/Kvps.key"
|
||||
content: "{{ ddclient_tsig_public_key_base64 | b64decode }}"
|
||||
notify: Restart podman ddclient
|
||||
|
||||
- name: Copy Kvps.private for {{ ddclient_namespace }}
|
||||
copy:
|
||||
dest: "/opt/{{ ddclient_namespace }}/Kvps.private"
|
||||
content: "{{ ddclient_tsig_private_key_base64 | b64decode }}"
|
||||
notify: Restart podman ddclient
|
||||
|
||||
- name: Start ddclient with podman for {{ ddclient_namespace }}
|
||||
containers.podman.podman_container:
|
||||
name: "{{ ddclient_container_name }}"
|
||||
hostname: "{{ ddclient_container_name }}"
|
||||
network: "{{ ddclient_network_mode }}"
|
||||
image: "{{ ddclient_container_registry }}/{{ ddclient_image_name }}:{{ ddclient_image_tag }}"
|
||||
state: present
|
||||
volumes: "{{ ddclient_volumes }}"
|
||||
|
||||
- name: Generate container systemd unit
|
||||
shell: "podman generate systemd {{ ddclient_container_name }}"
|
||||
register: ddclient_systemd_unit
|
||||
changed_when: False
|
||||
|
||||
- name: Create ddclient systemd unit
|
||||
copy:
|
||||
dest: "/etc/systemd/system/{{ ddclient_systemd_unit_name }}"
|
||||
content: "{{ ddclient_systemd_unit.stdout | regex_replace('^#.*', multiline=True) | trim }}"
|
||||
|
||||
- name: Enable ddclient systemd unit
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ ddclient_systemd_unit_name }}"
|
||||
enabled: yes
|
||||
state: started
|
||||
daemon_reload: yes
|
20
templates/ddclient.conf.j2
Normal file
20
templates/ddclient.conf.j2
Normal file
@ -0,0 +1,20 @@
|
||||
daemon=300
|
||||
syslog=yes
|
||||
mail-failure=root
|
||||
pid=/var/run/ddclient/ddclient.pid
|
||||
ssl=yes
|
||||
debug=yes
|
||||
verbose=yes
|
||||
|
||||
{% for host in ddclient_hosts %}
|
||||
use=web
|
||||
web=checkip.dyndns.org
|
||||
protocol=nsupdate
|
||||
server={{ host.dns_ip }}
|
||||
login=/usr/bin/nsupdate
|
||||
password={{ '/config' if ddclient_containerized else '/etc'}}/Kvps.key
|
||||
zone={{ host.domain }}
|
||||
ttl=60
|
||||
{{ host.name }}
|
||||
|
||||
{% endfor %}
|
Loading…
Reference in New Issue
Block a user