- name: Create DDNS Service
  hosts: all
  vars_files:
    - secrets/vars.yaml
  tasks:
  - name: Create container build dir
    ansible.builtin.file:
      path: /tmp/ddns
      state: directory
      mode: '0755'
  - name: Copy container build files
    copy:
      src: "{{ item }}" 
      dest: /tmp/ddns/
    with_items:
      - uv.lock
      - pyproject.toml
      - update.py
      - Containerfile
      - secrets/records.yaml
  - name: Run container build
    shell:
      cmd: podman build -t gitea.reeseapps.com/services/ddns:latest -f ./Containerfile
      chdir: /tmp/ddns/
  - name: Remove container build dir
    ansible.builtin.file:
      path: /tmp/ddns
      state: absent
  - name: Copy ddns.network
    template:
      src: ddns.network
      dest: /etc/containers/systemd/ddns.network
      owner: root
      group: root
      mode: '0644'
  - name: Template DDNS Container Service
    template:
      src: ddns.container
      dest: /etc/containers/systemd/ddns.container
      owner: root
      group: root
      mode: '0644'
  - name: Template DDNS Container Timer
    template:
      src: ddns.timer
      dest: /etc/systemd/system/ddns.timer
      owner: root
      group: root
      mode: '0644'
  - name: Reload ddns timer
    ansible.builtin.systemd_service:
      state: restarted
      name: ddns.timer
      enabled: true
      daemon_reload: true
  - name: Run ddns service
    ansible.builtin.systemd_service:
      state: restarted
      name: ddns.service
