/
/
/
This repo is destined for my server automations and setup.
1---
2# ============================================================================
3# Doorbell IoT Device Playbook
4# ============================================================================
5#
6# Deploys doorbell service with camera RTSP stream and MQTT integration
7# on a Raspberry Pi or similar edge device.
8#
9# PREREQUISITES:
10# - Fresh Debian 11+ or Ubuntu 20.04+ installation (ARM or x86)
11# - SSH access with sudo privileges for ansible_user
12# - Internet connectivity for package downloads
13# - Camera module connected and enabled
14# - MQTT broker accessible on the network
15#
16# ============================================================================
17
18- name: "Doorbell IoT Device Complete Setup"
19 hosts: doorbell
20 become: true
21 gather_facts: true
22
23 pre_tasks:
24 - name: Verify doorbell system requirements
25 assert:
26 that:
27 - ansible_distribution in ["Debian", "Ubuntu"]
28 - (ansible_distribution == "Debian" and ansible_distribution_major_version | int >= 11) or (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int >= 20)
29 - ansible_memtotal_mb >= 256
30 - ansible_processor_vcpus >= 1
31 fail_msg: |
32 Doorbell system requirements not met:
33 - Requires Debian 11+ or Ubuntu 20.04+
34 - Minimum 256MB RAM (found {{ ansible_memtotal_mb }}MB)
35 - Minimum 1 CPU core (found {{ ansible_processor_vcpus }})
36 success_msg: "Doorbell system requirements validated successfully"
37 tags: always
38
39 - name: Display doorbell deployment information
40 debug:
41 msg: |
42 ============================================================================
43 Doorbell IoT Device Installation Starting
44 ============================================================================
45 Target Host: {{ inventory_hostname }}
46 Target IP: {{ ansible_default_ipv4.address }}
47 OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
48 Architecture: {{ ansible_architecture }}
49 MQTT Host: {{ mqtt_host }}:{{ mqtt_port }}
50 RTSP Port: {{ rtsp_port }}
51 ============================================================================
52 tags: always
53
54 # ============================================================================
55 # ROLE EXECUTION ORDER
56 # ============================================================================
57
58 roles:
59 # 1. SYSTEM SETUP - Basic system configuration and packages
60 - role: system
61 tags: [system, setup]
62
63 # 2. DOCKER INSTALLATION - Install Docker using geerlingguy.docker
64 - role: geerlingguy.docker
65 tags: [docker, setup]
66
67 # 3. USER MANAGEMENT - Create user with proper groups
68 - role: user
69 tags: [user, setup]
70
71 # 4. DOCKER FRAMEWORK - Setup Docker directory structure
72 - role: docker-framework
73 tags: [docker, framework]
74
75 # 5. SECURITY HARDENING - Apply security settings
76 - role: geerlingguy.security
77 tags: [security, hardening]
78
79 # 6. DOORBELL - Deploy doorbell service
80 - role: doorbell
81 tags: [doorbell, iot]
82
83 # 7. MONITORING - System monitoring
84 - role: monitoring
85 tags: [monitoring, glances]
86
87 # ============================================================================
88 # POST-INSTALLATION TASKS
89 # ============================================================================
90
91 post_tasks:
92 - name: Verify Docker containers are running
93 command: docker ps --format "table {% raw %}{{.Names}}\t{{.Status}}{% endraw %}"
94 register: docker_status
95 changed_when: false
96 tags: [verification, docker]
97
98 - name: Check RTSP stream is accessible
99 ansible.builtin.wait_for:
100 host: "{{ ansible_default_ipv4.address }}"
101 port: "{{ rtsp_port }}"
102 timeout: 30
103 ignore_errors: true
104 register: rtsp_check
105 tags: [verification, rtsp]
106
107 - name: Display deployment completion summary
108 debug:
109 msg: |
110 ============================================================================
111 Doorbell IoT Device Installation Complete!
112 ============================================================================
113
114 Host: {{ inventory_hostname }}
115 IP Address: {{ ansible_default_ipv4.address }}
116 OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
117 Architecture: {{ ansible_architecture }}
118
119 Services:
120 - RTSP Stream: rtsp://{{ ansible_default_ipv4.address }}:{{ rtsp_port }} ({{ 'OK' if rtsp_check is succeeded else 'NOT READY' }})
121 - MQTT Broker: {{ mqtt_host }}:{{ mqtt_port }}
122
123 Docker Containers:
124 {{ docker_status.stdout | default('None running') | indent(10) }}
125
126 Useful Commands:
127 - Check container status: docker ps
128 - View doorbell logs: docker logs -f doorbell
129 - Test RTSP: ffprobe rtsp://{{ ansible_default_ipv4.address }}:{{ rtsp_port }}/doorbell
130
131 ============================================================================
132 tags: always
133