diff --git a/defaults/main.yml b/defaults/main.yml index 02fd73a..20abfd2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,6 +8,8 @@ ddclient_daemon: 300 ddclient_install_from_source: false ddclient_ssl: 'yes' +ddclient_backup: 'no' + ddclient_configs: - protocol: dnspark use: null @@ -20,3 +22,14 @@ ddclient_configs: password: password hosts: - host + +ddclient_owner: root +ddclient_group: root +ddclient_specify_cache: false +__ddclient_configuration_directory_mode: 0750 + + +newsyslog_config_dir: /usr/local/etc/newsyslog.conf.d +ddclient_newsyslog_template: ddclient_newsyslog +ddclient_newsyslog_file: ddclient +ddclient_newsyslog_count: 50 diff --git a/tasks/configure.yml b/tasks/configure.yml index 294e659..1d79c6e 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -3,33 +3,43 @@ ansible.builtin.file: path: "{{ __ddclient_configuration_directory }}" state: directory - owner: root - group: root - mode: 0750 + owner: "{{ ddclient_owner }}" + group: "{{ ddclient_group }}" + mode: "{{ __ddclient_configuration_directory_mode }}" - name: Create configuration file ansible.builtin.template: src: "{{ ddclient_configuration_template }}" dest: "{{ __ddclient_configuration_location }}" - owner: root - group: root + owner: "{{ ddclient_owner }}" + group: "{{ ddclient_group }}" + backup: "{{ ddclient_backup }}" mode: 0600 - name: Create the cache directory ansible.builtin.file: path: "{{ __ddclient_cache_directory }}" state: directory - owner: root - group: root + owner: "{{ ddclient_owner }}" + group: "{{ ddclient_group }}" mode: '0750' - name: Create the systemd file ansible.builtin.template: src: "{{ ddclient_service_template }}" dest: "{{ __ddclient_service_file }}" - owner: root - group: root + owner: "{{ ddclient_owner }}" + group: "{{ ddclient_group }}" mode: 0644 + when: ansible_os_family != 'FreeBSD' and not ddclient_install_from_source notify: - Disable_Service_DDClient - Enable_Service_DDClient + +- name: List some items + ansible.builtin.debug: + msg: + - "__ddclient_configuration_directory: {{ __ddclient_configuration_directory }}" + - "__ddclient_configuration_location: {{ __ddclient_configuration_location }}" + - "__ddclient_cache_director: {{ __ddclient_cache_directory }}" + tags: debug diff --git a/tasks/setup-FreeBSD.yml b/tasks/setup-FreeBSD.yml index aa932e4..7cad990 100644 --- a/tasks/setup-FreeBSD.yml +++ b/tasks/setup-FreeBSD.yml @@ -2,3 +2,21 @@ community.general.pkgng: name: ddclient state: present + +- ansible.builtin.set_fact: + ddclient_owner: "root" + ddclient_group: "wheel" + __ddclient_configuration_directory: /usr/local/etc/ddclient + __ddclient_configuration_directory_mode: 0755 + +- name: enable ddclient + sysrc: + name: ddclient_enable + state: present + value: "YES" + dest: /etc/rc.conf.d/ddclient + tags: ddclient + +- name: install newsyslog.conf file + template: src={{ ddclient_newsyslog_template }}.j2 dest={{ newsyslog_config_dir }}/{{ ddclient_newsyslog_file }}.conf owner=root group=wheel mode=0644 backup=yes + tags: ddclient,newsyslog diff --git a/templates/ddclient.conf.j2 b/templates/ddclient.conf.j2 index 2ef6664..6c76f48 100644 --- a/templates/ddclient.conf.j2 +++ b/templates/ddclient.conf.j2 @@ -1,12 +1,22 @@ #jinja2: trim_blocks: True -# {{ ansible_managed }} +# {{ ansible_managed }}. Template: {{ template_fullpath }} daemon={{ ddclient_daemon }} ssl={{ ddclient_ssl }} syslog=yes +verbose +facility=local3 +pid=/var/run/ddclient.pid +{% if ddclient_specify_cache %} +cache={{ __ddclient_cache_directory }}/ddclient.cache +{% endif %} + {% for config in ddclient_configs %} -{% if config.use is defined and config.use %} -use={{ config.use }} +{% if config.usev4 is defined and config.usev4 %} +usev4={{ config.usev4 }} +{% endif %} +{% if config.ifv4 is defined and config.ifv4 %} +ifv4={{ config.ifv4 }} {% endif %} protocol={{ config.protocol }} {% if config.server is defined and config.server %} @@ -24,6 +34,9 @@ mxpri={{ config.mxpri }}, {% if config.zone is defined and config.zone %} zone={{ config.zone }} {% endif %} +{% if config.ttl is defined and config.ttl %} +ttl={{ config.ttl }} +{% endif %} login={{ config.login }} password={{ config.password }} {{ config.hosts|join(', ')}} diff --git a/templates/ddclient.service.j2 b/templates/ddclient.service.j2 index 7469de3..bc8f475 100644 --- a/templates/ddclient.service.j2 +++ b/templates/ddclient.service.j2 @@ -1,4 +1,4 @@ -# {{ ansible_managed }} +# {{ ansible_managed }}. Template: {{ template_fullpath }} [Unit] Description=Dynamic DNS Update Client diff --git a/templates/ddclient_newsyslog.j2 b/templates/ddclient_newsyslog.j2 new file mode 100644 index 0000000..3f3a7a4 --- /dev/null +++ b/templates/ddclient_newsyslog.j2 @@ -0,0 +1,5 @@ +# Only .conf files /usr/local/etc/newsyslog.conf.d/ are pulled in by newsyslog +# + +# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] +/var/log/ddclient.log root:logcheck 640 {{ ddclient_newsyslog_count }} * $D0 B