- name: Create DDNS Service
  hosts: all
  vars_files:
    - secrets/vars.yaml
  tasks:
  - name: Create /etc/ddns dir
    ansible.builtin.file:
      path: /etc/ddns
      state: directory
      mode: '0755'
  - name: Copy ddns.network
    template:
      src: ddns.network
      dest: /etc/containers/systemd/ddns.network
      owner: root
      group: root
      mode: '0644'
  - name: Template DDNS Container Services
    template:
      src: ddns.container
      dest: /etc/containers/systemd/ddns.{{ item.record }}.container
      owner: root
      group: root
      mode: '0644'
    loop: "{{ records }}"
  - name: Template DDNS Container Timers
    template:
      src: ddns.timer
      dest: /etc/systemd/system/ddns.{{ item.record }}.timer
      owner: root
      group: root
      mode: '0644'
    loop: "{{ records }}"
  - name: Reload ddns timer
    ansible.builtin.systemd_service:
      state: restarted
      name: ddns.{{ item.record }}.timer
      enabled: true
      daemon_reload: true
    loop: "{{ records }}"
  - name: Run ddns service
    ansible.builtin.systemd_service:
      state: restarted
      name: ddns.{{ item.record }}.service
    loop: "{{ records }}"
