---
- name: Setup Cloudflared
  hosts: portfolio.lab.local
  gather_facts: true

  tasks:
    - name: Create cloudflared directory
      ansible.builtin.file:
        path: "/home/{{ admin_user }}/containers/cloudflared"
        state: directory
        mode: "0755"

    - name: Deploy Cloudflared Systemd Service
      become: true
      ansible.builtin.template:
        src: "./templates/cloudflared.service.j2"
        dest: "/etc/systemd/system/cloudflared.service"
        mode: "0644"

    - name: Start and enable Cloudflared service
      become: true
      ansible.builtin.systemd_service:
        name: cloudflared.service
        state: started
        enabled: true
        daemon_reload: true
