Added role for dynamic dns

This commit is contained in:
Scott Crossen
2020-10-13 16:18:38 -07:00
parent 5abd511368
commit 1f988969a5
15 changed files with 222 additions and 0 deletions

View File

@ -0,0 +1,4 @@
- set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['ddclient'] }}"
when: "matrix_dynamic_dns_enabled|bool"

View File

@ -0,0 +1,24 @@
---
- name: Ensure ddclient domain config exists
template:
src: "{{ role_path }}/templates/ddclient.conf.j2"
dest: "/etc/ddclient.conf"
mode: 0600
register: matrix_dynamic_dns_ddclient_domain_config
- name: Ensure ddclient client config directory exists
file:
path: "/etc/default"
state: directory
mode: 0700
owner: "{{ user_username }}"
group: "{{ user_groupname }}"
- name: Ensure ddclient client config exists
template:
src: "{{ role_path }}/templates/ddclient.j2"
dest: "/etc/default/ddclient"
mode: 0600
register: matrix_dynamic_dns_ddclient_client_config

View File

@ -0,0 +1,28 @@
- import_tasks: "{{ role_path }}/tasks/init.yml"
tags:
- always
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
when: "run_setup|bool and matrix_dynamic_dns_enabled|bool"
tags:
- setup-all
- setup-dynamic-dns
- import_tasks: "{{ role_path }}/tasks/install.yml"
when: "run_setup|bool and matrix_dynamic_dns_enabled|bool"
tags:
- setup-all
- setup-dynamic-dns
- import_tasks: "{{ role_path }}/tasks/platform/main.yml"
when: "run_setup|bool"
tags:
- setup-all
- setup-dynamic-dns
- import_tasks: "{{ role_path }}/tasks/uninstall.yml"
when: "run_setup|bool and not matrix_dynamic_dns_enabled|bool"
tags:
- setup-all
- setup-dynamic-dns

View File

@ -0,0 +1,16 @@
---
- name: Ensure ddclient is installed
pacman:
name: ddclient
state: latest
when: "run_setup|bool and matrix_dynamic_dns_enabled|bool"
- name: Ensure ddclient is uninstalled
pacman:
name: ddclient
state: absent
update_cache: true
become: true
when: "run_setup|bool and not matrix_dynamic_dns_enabled|bool"

View File

@ -0,0 +1,23 @@
---
- name: Ensure yum packages are installed
yum:
name: epel-release
state: latest
update_cache: yes
when: "run_setup|bool and matrix_dynamic_dns_enabled|bool"
- name: Ensure ddclient is installed
yum:
name: ddclient
state: latest
when: "run_setup|bool and matrix_dynamic_dns_enabled|bool"
- name: Ensure ddclient is uninstalled
yum:
name:
- ddclient
- epel-release
state: absent
when: "run_setup|bool and not matrix_dynamic_dns_enabled|bool"

View File

@ -0,0 +1,18 @@
---
- name: Ensure ddclient is installed
apt:
name: ddclient
state: present
update_cache: true
become: true
when: "run_setup|bool and matrix_dynamic_dns_enabled|bool"
- name: Ensure ddclient is uninstalled
apt:
name: ddclient
state: absent
update_cache: true
become: true
when: "run_setup|bool and not matrix_dynamic_dns_enabled|bool"

View File

@ -0,0 +1,11 @@
---
- include_tasks: "{{ role_path }}/tasks/platform/centos.yml"
when: ansible_distribution == 'CentOS'
# The instructions are the same for Debian, Ubuntu, and Raspbian
- include_tasks: "{{ role_path }}/tasks/platform/debian.yml"
when: ansible_distribution == 'Debian'
- include_tasks: "{{ role_path }}/tasks/platform/archlinux.yml"
when: ansible_distribution == 'Archlinux'

View File

@ -0,0 +1,31 @@
---
- name: Check existence of ddclient.service
stat:
path: "{{ systemd_path }}/ddclient.service"
register: matrix_dynamic_dns_ddclient_service_stat
- name: Ensure ddclient.service is stopped
service:
name: dynamic-dns
state: stopped
daemon_reload: yes
when: "matrix_dynamic_dns_ddclient_service_stat.stat.exists"
- name: Ensure systemd reloaded after ddclient.service removal
service:
daemon_reload: yes
when: "matrix_dynamic_dns_ddclient_service_stat.stat.exists"
- name: Ensure ddclient.service doesn't exist
file:
path: "{{ systemd_path }}/ddclient.service"
state: absent
when: "matrix_dynamic_dns_ddclient_service_stat.stat.exists"
- name: Ensure ddclient configuration files don't exist
file:
path:
- "etc/ddclient.conf"
- "etc/default/ddclient"
state: absent

View File

@ -0,0 +1,19 @@
---
- name: Fail if required settings not defined
fail:
msg: >-
You need to define a required configuration setting (`{{ item }}`).
when: "vars[item] == ''"
with_items:
- "matrix_dynamic_dns_username"
- "matrix_dynamic_dns_password"
- "matrix_domain"
- "matrix_dynamic_dns_provider"
- "matrix_dynamic_dns_mode"
- name: Fail if dynamic dns mode is incorrect
fail:
msg: >-
matrix_dynamic_dns_mode needs to be set to 'daemon' or 'startup'
when: "matrix_dynamic_dns_enabled and matrix_dynamic_dns_mode != 'daemon' and matrix_dynamic_dns_mode != 'dhcp'"