frigate/install.yaml

218 lines
7.6 KiB
YAML

- name: Install Frigate
hosts: Barad-dur
vars_prompt:
- name: ipgeolocation_api_key
prompt: Enter API key for IPGeolocation
- name: wyze_email
prompt: Enter email for Wyze account
- name: wyze_password
prompt: Enter password for Wyze account
- name: wyze_api_id
prompt: Enter API ID for Wyze account
- name: wyze_api_key
prompt: Enter API key for Wyze account
- name: garage_rtsp_password
prompt: Enter password for garage camera RTSP stream user motion
- name: front_door_rtsp_password
prompt: Enter password for front door camera RTSP stream user motion
- name: doorbell_rtsp_password
prompt: Enter password for doorbell camera RTSP stream user admin
- name: driveway_rtsp_password
prompt: Enter password for driveway camera RTSP stream user admin
- name: back_door_rtsp_password
prompt: Enter password for back door camera RTSP stream user motion
- name: family_room_rtsp_password
prompt: Enter password for family room camera RTSP stream user frigate
- name: office_rtsp_password
prompt: Enter password for office camera RTSP stream user frigate
tasks:
- name: Create Frigate config Docker volume directory
become: true
ansible.builtin.file:
path: /data/frigate-config
state: directory
- name: Create Frigate config Docker volume
community.docker.docker_volume:
volume_name: frigate-config
driver: local
driver_options:
type: none
o: bind
device: /data/frigate-config
state: present
- name: Create Frigate media Docker volume directory
become: true
ansible.builtin.file:
path: /mnt/nvr_storage/frigate
state: directory
- name: Create Frigate media Docker volume
community.docker.docker_volume:
volume_name: frigate-media
driver: local
driver_options:
type: none
o: bind
device: /mnt/nvr_storage/frigate
state: present
- name: Copy Nginx config file for Frigate
become: true
ansible.builtin.copy:
src: conf/nginx.conf
dest: /data/nginx-config/frigate.conf
mode: preserve
- name: Copy server config file for Frigate
become: true
ansible.builtin.copy:
src: conf/config.yaml
dest: /data/frigate-config/config.yaml
mode: preserve
- name: Create temporary Docker build directory for frigate-notify
ansible.builtin.tempfile:
state: directory
register: docker_build_dir
- name: Copy Docker build directory
ansible.builtin.copy:
src: notify/
dest: '{{docker_build_dir.path}}'
mode: preserve
- name: Build frigate-notify Docker image
community.docker.docker_image:
build:
path: '{{docker_build_dir.path}}'
name: frigate-notify
tag: latest
source: build
force_source: true
state: present
- name: Remove temporary Docker build directory for frigate-notify
ansible.builtin.file:
path: '{{docker_build_dir.path}}'
state: absent
- name: Create temporary Docker build directory for frigate-webcontrol
ansible.builtin.tempfile:
state: directory
register: docker_build_dir
- name: Copy Docker build directory
ansible.builtin.copy:
src: webcontrol/
dest: '{{docker_build_dir.path}}'
mode: preserve
- name: Build frigate-webcontrol Docker image
community.docker.docker_image:
build:
path: '{{docker_build_dir.path}}'
name: frigate-webcontrol
tag: latest
source: build
force_source: true
state: present
- name: Remove temporary Docker build directory for frigate-webcontrol
ansible.builtin.file:
path: '{{docker_build_dir.path}}'
state: absent
- name: Create temporary Docker build directory for frigate-uptime
ansible.builtin.tempfile:
state: directory
register: docker_build_dir
- name: Copy Docker build directory
ansible.builtin.copy:
src: uptime-go/
dest: '{{docker_build_dir.path}}'
mode: preserve
- name: Build frigate-uptime Docker image
community.docker.docker_image:
build:
path: '{{docker_build_dir.path}}'
name: frigate-uptime
tag: latest
source: build
force_source: true
state: present
- name: Remove temporary Docker build directory for frigate-uptime
ansible.builtin.file:
path: '{{docker_build_dir.path}}'
state: absent
- name: Read homelab config
ansible.builtin.slurp:
src: '{{ansible_user_dir}}/.homelab.json'
register: homelab_config_file
- name: Set homelab_config variable
ansible.builtin.set_fact:
homelab_config: '{{homelab_config_file.content|b64decode|from_json}}'
- name: Insert into Postgres table service
vars:
frigate_config:
ipgeolocation:
api_key: '{{ipgeolocation_api_key}}'
wyze:
email: '{{wyze_email}}'
password: '{{wyze_password}}'
api_id: '{{wyze_api_id}}'
api_key: '{{wyze_api_key}}'
rtsp:
garage:
password: '{{garage_rtsp_password}}'
front_door:
password: '{{front_door_rtsp_password}}'
doorbell:
password: '{{doorbell_rtsp_password}}'
driveway:
password: '{{driveway_rtsp_password}}'
back_door:
password: '{{back_door_rtsp_password}}'
family_room:
password: '{{family_room_rtsp_password}}'
office:
password: '{{office_rtsp_password}}'
community.postgresql.postgresql_query:
login_host: '{{homelab_config.database.host}}'
login_user: '{{homelab_config.database.user}}'
login_password: '{{homelab_config.database.password}}'
db: '{{homelab_config.database.name}}'
query: 'INSERT INTO service (name, host, source, config) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING;'
positional_args:
- '{{item.name}}'
- '{{item.host}}'
- '{{item.source}}'
- '{{item.config}}'
with_items:
- {name: frigate, host: '{{ansible_hostname}}', source: gitea/ashish/frigate/master, config: '{{frigate_config|to_json}}'}
- name: Insert into Postgres table service_port
community.postgresql.postgresql_query:
login_host: '{{homelab_config.database.host}}'
login_user: '{{homelab_config.database.user}}'
login_password: '{{homelab_config.database.password}}'
db: '{{homelab_config.database.name}}'
query: 'INSERT INTO service_port (service, port, domain, reverse_proxy, reverse_proxy_port) VALUES (%s, %s, %s, %s, %s) ON CONFLICT DO NOTHING;'
positional_args:
- '{{item.service}}'
- '{{item.port}}'
- '{{item.domain}}'
- '{{item.reverse_proxy}}'
- '{{item.reverse_proxy_port}}'
with_items:
- {service: frigate, port: 10000, domain: null, reverse_proxy: nginx_barad-dur, reverse_proxy_port: 443}
- {service: frigate, port: 10001, domain: null, reverse_proxy: nginx_barad-dur, reverse_proxy_port: 443}
- name: Insert into Postgres table service_data
community.postgresql.postgresql_query:
login_host: '{{homelab_config.database.host}}'
login_user: '{{homelab_config.database.user}}'
login_password: '{{homelab_config.database.password}}'
db: '{{homelab_config.database.name}}'
query: 'INSERT INTO service_data (service, data_name, storage_type, source) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING;'
positional_args:
- '{{item.service}}'
- '{{item.data_name}}'
- '{{item.storage_type}}'
- '{{item.source}}'
with_items:
- {service: frigate, data_name: config, storage_type: docker, source: frigate-config}
- {service: frigate, data_name: media, storage_type: docker, source: frigate-data}