--- # - 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') }}" when: handle_ufw - name: Enable motion web control in ufw ufw: rule: allow from_ip: "{{ item }}" port: "{{ motion_config['webcontrol_port'] }}" loop: "{{ localnetworks }}" when: handle_ufw - 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 - 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 when: transfer_recordings - name: Enable timer unit to transfer recordings systemd: daemon_reload: true name: transfer_recordings.timer enabled: true when: transfer_recordings - name: Ensure motion_hass is configured template: src: templates/motion_hass.conf.j2 dest: /etc/motion_hass.conf backup: yes - 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 - name: Configure logrotate for HomeAssistant integration blockinfile: path: /etc/logrotate.d/motion_hass block: | /var/lib/motion/log/motion_hass.log { daily rotate 30 compress } create: true - name: Configure logrotate for process_motion_event blockinfile: path: /etc/logrotate.d/process_motion_event block: | /var/lib/motion/log/process_motion_event.log { daily rotate 30 compress } create: true - name: Configure logrotate for send_msg blockinfile: path: /etc/logrotate.d/send_msg_motion block: | /var/lib/motion/log/send_msg.log { daily rotate 30 compress } create: true - name: Ensure motion_bot password file exists copy: dest: "{{ motion_bot_ntfy_password_file }}" content: "{{ motion_bot_ntfy_password }}" mode: 0600 owner: motion group: motion when: motion_bot_ntfy_server != ''