--- # - 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 - 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