2022-10-11 09:19:01 +02:00
|
|
|
---
|
|
|
|
# - name: Ensure motion mount folder exists
|
|
|
|
# file:
|
|
|
|
# path: "{{ target_dir }}"
|
|
|
|
# state: directory
|
|
|
|
# owner: motion
|
|
|
|
# group: motion
|
|
|
|
# mode: 0755
|
|
|
|
# - name: Ensure motion shared folder is mounted
|
|
|
|
# ansible.posix.mount:
|
|
|
|
# path: "{{ target_dir }}"
|
|
|
|
# src: 192.168.1.7:/motion
|
|
|
|
# fstype: nfs4
|
|
|
|
# opts: _netdev
|
|
|
|
# state: present
|
|
|
|
# - name: Ensure mail notification script is deployed
|
|
|
|
# copy:
|
|
|
|
# src: ../scripts/mail_notification.sh
|
|
|
|
# dest: /usr/local/bin/mail_notification.sh
|
|
|
|
# owner: root
|
|
|
|
# group: root
|
|
|
|
# mode: 0755
|
|
|
|
- name: Ensure motion group exists
|
|
|
|
group:
|
|
|
|
name: motion
|
|
|
|
|
|
|
|
- name: Ensure motion members are configured
|
|
|
|
user:
|
|
|
|
name: "{{ item }}"
|
|
|
|
append: true
|
|
|
|
groups:
|
|
|
|
- motion
|
|
|
|
loop: "{{ motion_members }}"
|
|
|
|
|
|
|
|
- name: Ensure motion's log folder exists
|
|
|
|
file:
|
|
|
|
path: "{{ motion_config['log_file'] | dirname }}"
|
|
|
|
state: directory
|
|
|
|
owner: motion
|
|
|
|
when: "'log_file' in motion_config"
|
|
|
|
|
|
|
|
- name: Ensure motion can write to log folder
|
|
|
|
file:
|
|
|
|
path: "{{ motion_config['log_file'] }}"
|
|
|
|
state: touch
|
|
|
|
owner: motion
|
|
|
|
when: "'log_file' in motion_config"
|
|
|
|
|
|
|
|
- name: Ensure camera configurations folder exists
|
|
|
|
file:
|
|
|
|
path: "{{ motion_config['camera_dir'] | default('/etc/motion/conf.g') }}"
|
|
|
|
state: directory
|
|
|
|
owner: motion
|
|
|
|
|
|
|
|
- name: Configure motion
|
|
|
|
template:
|
|
|
|
src: templates/motion.conf.j2
|
|
|
|
dest: /etc/motion/motion.conf
|
|
|
|
backup: yes
|
|
|
|
notify: Restart motion service
|
|
|
|
|
|
|
|
- name: Configure cameras
|
|
|
|
template:
|
|
|
|
src: templates/camera.conf.j2
|
|
|
|
dest: "{{ motion_config['camera_dir'] }}/{{ item.camera_name }}.conf"
|
|
|
|
backup: yes
|
|
|
|
loop: "{{ motion_config['cameras'] }}"
|
|
|
|
notify: Restart motion service
|
|
|
|
|
|
|
|
- name: Ensure target directories are writable by motion
|
|
|
|
file:
|
|
|
|
path: "{{ item.target_dir }}"
|
|
|
|
owner: motion
|
|
|
|
state: directory
|
|
|
|
loop: "{{ motion_config['cameras'] }}"
|
|
|
|
when: item.target_dir is defined
|
|
|
|
|
|
|
|
- name: Check if there is a default file for initd
|
|
|
|
stat:
|
|
|
|
path: /etc/default/motion
|
|
|
|
register: motion_default_file
|
|
|
|
|
|
|
|
- name: Ensure motion daemon is enabled
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/default/motion
|
|
|
|
regexp: '^start_motion_daemon'
|
|
|
|
line: 'start_motion_daemon=yes'
|
|
|
|
when: motion_default_file.stat.exists
|
|
|
|
|
|
|
|
- name: Ensure motion service is running and enabled
|
|
|
|
service:
|
|
|
|
name: motion
|
|
|
|
state: started
|
|
|
|
enabled: true
|
|
|
|
|
|
|
|
- name: Enable motion web stream in ufw
|
|
|
|
ufw:
|
|
|
|
rule: allow
|
|
|
|
port: "{{ item.stream_port }}"
|
|
|
|
loop: "{{ motion_config['cameras'] | selectattr('stream_port', 'defined') }}"
|
|
|
|
|
|
|
|
- name: Enable motion web control in ufw
|
|
|
|
ufw:
|
|
|
|
rule: allow
|
|
|
|
port: "{{ motion_config['webcontrol_port'] }}"
|
|
|
|
|
|
|
|
- name: Ensure motion can read signal configuration
|
|
|
|
ansible.posix.acl:
|
|
|
|
path: /etc/signal_configuration
|
|
|
|
entity: motion
|
|
|
|
etype: user
|
|
|
|
permissions: 'rx'
|
|
|
|
recursive: true
|
|
|
|
state: present
|
|
|
|
default: true
|
2023-03-11 10:27:54 +01:00
|
|
|
|
|
|
|
- name: Deploy service unit to transfer recordings
|
|
|
|
copy:
|
|
|
|
src: files/transfer_recordings.service
|
|
|
|
dest: /etc/systemd/system/transfer_recordings.service
|
|
|
|
notify: Reload systemd
|
|
|
|
|
|
|
|
- name: Deploy timer unit to transfer recordings
|
|
|
|
copy:
|
|
|
|
src: files/transfer_recordings.timer
|
|
|
|
dest: /etc/systemd/system/transfer_recordings.timer
|
|
|
|
notify: Reload systemd
|
|
|
|
|
|
|
|
- name: Enable service unit to transfer recordings
|
|
|
|
systemd:
|
|
|
|
daemon_reload: true
|
|
|
|
name: transfer_recordings.service
|
|
|
|
enabled: true
|
|
|
|
|
|
|
|
- name: Enable timer unit to transfer recordings
|
|
|
|
systemd:
|
|
|
|
daemon_reload: true
|
|
|
|
name: transfer_recordings.timer
|
|
|
|
enabled: true
|
2023-03-17 14:46:02 +01:00
|
|
|
|
|
|
|
- name: Ensure motion_hass is configured
|
|
|
|
template:
|
|
|
|
src: templates/motion_hass.conf.j2
|
|
|
|
dest: /etc/motion_hass.conf
|
|
|
|
backup: yes
|
2023-03-17 14:48:59 +01:00
|
|
|
|
|
|
|
- name: Deploy service unit for HomeAssistant integration
|
|
|
|
copy:
|
|
|
|
src: files/motion_hass.service
|
|
|
|
dest: /etc/systemd/system/motion_hass.service
|
|
|
|
notify: Reload systemd
|
|
|
|
|
|
|
|
- name: Deploy timer unit for HomeAssistant integration
|
|
|
|
copy:
|
|
|
|
src: files/motion_hass.timer
|
|
|
|
dest: /etc/systemd/system/motion_hass.timer
|
|
|
|
notify: Reload systemd
|
|
|
|
|
|
|
|
- name: Enable service unit for HomeAssistant integration
|
|
|
|
systemd:
|
|
|
|
daemon_reload: true
|
|
|
|
name: motion_hass.service
|
|
|
|
enabled: true
|
|
|
|
|
|
|
|
- name: Enable timer unit for HomeAssistant integration
|
|
|
|
systemd:
|
|
|
|
daemon_reload: true
|
|
|
|
name: motion_hass.timer
|
|
|
|
enabled: true
|