/
/
/
Ansible role that deployes services on my runner machine
1---
2# Runner Services - Frigate CCTV System
3
4- name: Create Frigate configuration directory structure
5 file:
6 path: "{{ item }}"
7 state: directory
8 owner: "{{ runner_user }}"
9 group: "{{ runner_group }}"
10 mode: '0775'
11 loop:
12 - "{{ frigate_config_dir }}"
13 - "{{ frigate_config_dir }}/config"
14 - "{{ frigate_config_dir }}/config/models"
15 - "{{ frigate_config_dir }}/manager"
16
17- name: Set group sticky bit on Frigate directories for permission inheritance
18 file:
19 path: "{{ item }}"
20 state: directory
21 mode: "g+s"
22 loop:
23 - "{{ frigate_config_dir }}"
24 - "{{ frigate_config_dir }}/config"
25 - "{{ frigate_config_dir }}/config/models"
26
27- name: Copy coco labels
28 ansible.builtin.copy:
29 src: coco_labels.txt
30 dest: "{{ frigate_config_dir }}/config/models/coco_labels.txt"
31 owner: "{{ runner_user }}"
32 group: "{{ runner_group }}"
33 mode: '0664'
34 when: frigate_hardware_acceleration == 'nvenc'
35
36- name: Copy frigate manager script
37 ansible.builtin.copy:
38 src: frigate-manager/manager.py
39 dest: "{{ frigate_config_dir }}/manager/manager.py"
40 owner: "{{ runner_user }}"
41 group: "{{ runner_group }}"
42 mode: '0664'
43 notify: restart frigate
44
45- name: Create manager Dockerfile
46 template:
47 src: frigate-Dockerfile.j2
48 dest: "{{ frigate_config_dir }}/manager/Dockerfile"
49 owner: "{{ runner_user }}"
50 group: "{{ runner_group }}"
51 mode: '0664'
52 notify: restart frigate
53
54- name: Generate Frigate profile configuration files
55 template:
56 src: frigate-config.yml.j2
57 dest: "{{ frigate_config_dir }}/config/config.{{ item.key }}.yml"
58 owner: "{{ runner_user }}"
59 group: "{{ runner_group }}"
60 mode: '0777'
61 backup: yes
62 vars:
63 profile_name: "{{ item.key }}"
64 profile: "{{ item.value }}"
65 loop: "{{ frigate_profiles | dict2items }}"
66 notify: restart frigate
67
68- name: Set initial active config from default profile
69 ansible.builtin.copy:
70 src: "{{ frigate_config_dir }}/config/config.{{ (frigate_profiles | dict2items | selectattr('value.default_profile', 'equalto', true) | map(attribute='key') | first) }}.yml"
71 dest: "{{ frigate_config_dir }}/config/config.yml"
72 remote_src: yes
73 owner: "{{ runner_user }}"
74 group: "{{ runner_group }}"
75 mode: '0777'
76 force: no
77
78# GPU configuration is handled directly in service templates - no separate config file needed
79
80- name: Check GPU availability and warn if configuration mismatch
81 debug:
82 msg: |
83 WARNING: Frigate hardware acceleration setting '{{ frigate_hardware_acceleration }}' may not be available.
84 {% if frigate_hardware_acceleration in ['nvdec', 'nvenc'] and not ansible_facts.get('gpu_info', {}).get('nvidia_gpu_detected', false) %}
85 NVIDIA GPU not detected. Falling back to CPU-only processing.
86 {% elif frigate_hardware_acceleration == 'qsv' and not ansible_facts.get('intel_gpu_detected', false) %}
87 Intel GPU not detected. Falling back to CPU-only processing.
88 {% elif frigate_hardware_acceleration == 'vaapi' and ansible_facts.get('vaapi_devices', []) | length == 0 %}
89 VAAPI devices not found. Falling back to CPU-only processing.
90 {% endif %}
91 Consider setting frigate_hardware_acceleration to "none" for CPU-only processing.
92 when: >
93 (frigate_hardware_acceleration in ['nvdec', 'nvenc'] and not ansible_facts.get('gpu_info', {}).get('nvidia_gpu_detected', false)) or
94 (frigate_hardware_acceleration == 'qsv' and not ansible_facts.get('intel_gpu_detected', false)) or
95 (frigate_hardware_acceleration == 'vaapi' and ansible_facts.get('vaapi_devices', []) | length == 0)
96
97- name: Create Frigate Docker Compose file
98 template:
99 src: frigate-compose.yml.j2
100 dest: "{{ frigate_config_dir }}/docker-compose.yml"
101 owner: "{{ runner_user }}"
102 group: "{{ runner_group }}"
103 mode: '0664'
104 notify: restart frigate
105
106- name: Start Frigate service
107 community.docker.docker_compose_v2:
108 project_src: "{{ frigate_config_dir }}"
109 state: present
110 register: frigate_start_result
111 check_mode: no
112
113- name: Wait for Frigate to be healthy
114 uri:
115 url: "http://localhost:{{ frigate_port }}/api/config"
116 method: GET
117 status_code: 200
118 register: frigate_health
119 until: frigate_health.status == 200
120 retries: 30
121 delay: 10
122 when: frigate_start_result is changed
123 check_mode: no
124
125- name: Display Frigate deployment summary
126 debug:
127 msg: |
128 Frigate CCTV System Deployment:
129 - Status: {{ 'Started' if frigate_start_result is changed else 'Already running' }}
130 - Web UI: http://{{ ansible_default_ipv4.address }}:{{ frigate_port }}
131 - RTSP Re-stream: rtsp://{{ ansible_default_ipv4.address }}:{{ frigate_rtsp_port }}
132 - Configuration: {{ frigate_config_dir }}/config/config.yml
133 - Profiles: {{ frigate_profiles | dict2items | map(attribute='key') | join(', ') }}
134 - Active Profile: {{ (frigate_profiles | dict2items | selectattr('value.default_profile', 'equalto', true) | map(attribute='key') | first) }} (default)
135 - Data Storage: {{ frigate_data_dir }}
136 - Cameras Configured: {{ frigate_cameras | length }}
137 - MQTT: {{ 'Enabled' if frigate_mqtt_enabled else 'Disabled' }}
138 - Manager: {{ 'Enabled' if frigate_manager_enabled | default(true) else 'Disabled' }}
139 - Hardware Acceleration: {{ frigate_hardware_acceleration }}
140
141 Profile Switch: mosquitto_pub -h {{ mqtt_host }} -t frigate/profile/set -m "home"
142