IOT Playbook updated with docker networks and caddy.

This commit is contained in:
tanshu committed 2025-07-09 01:16:10 +00:00
1 parent 7c2a66540f
commit 3ff953acdb
13 files changed
+73 -62

No files matched your search

+6 -5
View File
@@ -6,8 +6,9 @@
- vars/default.yml - vars/default.yml
roles: roles:
# - mosquitto - network
# - influxdb - mosquitto
# - nodered - influxdb
# - grafana - nodered
- nginx - grafana
- caddy
+7
View File
@@ -0,0 +1,7 @@
caddy_container: caddy
caddyfile_path: /var/lib/caddy/conf/Caddyfile
snippet_block: |
{{ host }} {
reverse_proxy {{ grafana_container }}:3000
}
+7
View File
@@ -0,0 +1,7 @@
---
# Handlers for Nginx role
- name: Restart caddy container
docker_container:
name: "{{ caddy_container }}"
state: started
restart: true
+22
View File
@@ -0,0 +1,22 @@
---
- name: Read current Caddyfile
ansible.builtin.slurp:
path: "{{ caddyfile_path }}"
register: caddyfile_raw
- name: Decode Caddyfile content
set_fact:
caddyfile_content: "{{ caddyfile_raw['content'] | b64decode }}"
- name: Check if snippet already exists
set_fact:
snippet_present: "{{ snippet_block in caddyfile_content }}"
- name: Add snippet if missing
ansible.builtin.blockinfile:
path: "{{ caddyfile_path }}"
marker: "# {mark} Ansible managed Caddy snippet for {{ host }}"
block: "{{ snippet_block }}"
create: yes
when: not snippet_present
notify: Restart caddy container
+3 -5
View File
@@ -27,15 +27,13 @@
restart_policy: "unless-stopped" restart_policy: "unless-stopped"
user: "{{ getent_passwd[grafana_user][1] }}:{{ getent_passwd[grafana_user][2] }}" user: "{{ getent_passwd[grafana_user][1] }}:{{ getent_passwd[grafana_user][2] }}"
env: env:
GF_SERVER_ROOT_URL: "https://{{ http_host }}" GF_SERVER_ROOT_URL: "https://{{ host }}"
GF_INSTALL_PLUGINS: "grafana-clock-panel, grafana-simple-json-datasource, natel-discrete-panel, briangann-gauge-panel, vonage-status-panel, neocat-cal-heatmap-panel, natel-plotly-panel" GF_INSTALL_PLUGINS: "grafana-clock-panel, grafana-simple-json-datasource, natel-discrete-panel, briangann-gauge-panel, vonage-status-panel, neocat-cal-heatmap-panel, natel-plotly-panel"
GF_AUTH_ANONYMOUS_ENABLED: "true" GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_NAME: "Public" GF_AUTH_ANONYMOUS_ORG_NAME: "Public"
GF_AUTH_ANONYMOUS_ORG_ROLE: "Viewer" GF_AUTH_ANONYMOUS_ORG_ROLE: "Viewer"
GF_AUTH_ANONYMOUS_HIDE_VERSION: "true" GF_AUTH_ANONYMOUS_HIDE_VERSION: "true"
links: networks:
- "{{ influx_container }}:influx" - name: "{{ docker_network }}"
published_ports:
- 127.0.0.1:3005:3000
volumes: volumes:
- "{{ grafana_directory }}:/var/lib/grafana" - "{{ grafana_directory }}:/var/lib/grafana"
+4 -2
View File
@@ -42,8 +42,10 @@
state: started state: started
restart_policy: "unless-stopped" restart_policy: "unless-stopped"
user: "{{ getent_passwd[influx_user][1] }}:{{ getent_passwd[influx_user][2] }}" user: "{{ getent_passwd[influx_user][1] }}:{{ getent_passwd[influx_user][2] }}"
published_ports: networks:
- 127.0.0.1:8088:8086 - name: "{{ docker_network }}"
aliases:
- influx
volumes: volumes:
- "{{ influx_directory }}/data:/var/lib/influxdb2" - "{{ influx_directory }}/data:/var/lib/influxdb2"
- "{{ influx_directory }}/config:/etc/influxdb2" - "{{ influx_directory }}/config:/etc/influxdb2"
+8 -8
View File
@@ -35,10 +35,6 @@
owner: 1883 # "{{ mosquitto_user }}" owner: 1883 # "{{ mosquitto_user }}"
mode: 0646 mode: 0646
# - name: Check if Mosquitto passwd file exists
# stat: path="{{ mosquitto_directory }}/config/passwd"
# register: status
- name: Ensure Mosquitto passwd file exists - name: Ensure Mosquitto passwd file exists
template: template:
src: "files/passwd" src: "files/passwd"
@@ -47,9 +43,6 @@
owner: 1883 # "{{ mosquitto_user }}" owner: 1883 # "{{ mosquitto_user }}"
mode: 0646 mode: 0646
- name: Encrypt the docker file
command: docker exec -i mosquitto mosquitto_passwd -U /mosquitto/config/passwd
- name: Ensure Mosquitto Log Directory exists - name: Ensure Mosquitto Log Directory exists
file: file:
path: "{{ mosquitto_directory }}/log" path: "{{ mosquitto_directory }}/log"
@@ -73,10 +66,17 @@
state: started state: started
restart_policy: "unless-stopped" restart_policy: "unless-stopped"
# user: 0:0 # "{{ getent_passwd[mosquitto_user][1] }}:{{ getent_passwd[mosquitto_user][2] }}" # user: 0:0 # "{{ getent_passwd[mosquitto_user][1] }}:{{ getent_passwd[mosquitto_user][2] }}"
networks:
- name: "{{ docker_network }}"
aliases:
- mqtt
published_ports: published_ports:
- 127.0.0.1:9001:9001
- 1883:1883 - 1883:1883
volumes: volumes:
- "{{ mosquitto_directory }}/config:/mosquitto/config" - "{{ mosquitto_directory }}/config:/mosquitto/config"
- "{{ mosquitto_directory }}/data:/mosquitto/data" - "{{ mosquitto_directory }}/data:/mosquitto/data"
- "{{ mosquitto_directory }}/log:/mosquitto/log" - "{{ mosquitto_directory }}/log:/mosquitto/log"
- name: Encrypt the docker file
command: docker exec -i mosquitto mosquitto_passwd -U /mosquitto/config/passwd
+9
View File
@@ -0,0 +1,9 @@
---
# Tasks for Mosquitto role
- name: Ensure 'iot' Docker network exists
docker_network:
name: "{{ docker_network }}"
state: present
connected:
- caddy
appends: yes
-2
View File
@@ -1,2 +0,0 @@
---
# Default variables for Nginx role
-6
View File
@@ -1,6 +0,0 @@
---
# Handlers for Nginx role
- name: Reload Nginx
service:
name: nginx
state: reloaded
-24
View File
@@ -1,24 +0,0 @@
---
# Tasks for Nginx role
- name: Check if Nginx conf file exists
stat:
path: "/etc/nginx/sites-available/{{ http_conf }}"
register: status
- name: No need to reload Nginx
debug:
msg: "No need to reload Nginx as sites-available entries have already been created"
- name: Set Nginx conf file
when: status.stat.exists == false
template:
src: "files/nginx.conf.j2"
dest: "/etc/nginx/sites-available/{{ http_conf }}"
- name: Enable new site
when: status.stat.exists == false
file:
src: "/etc/nginx/sites-available/{{ http_conf }}"
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
state: link
notify: Reload Nginx
+2 -5
View File
@@ -28,10 +28,7 @@
user: "{{ getent_passwd[nodered_user][1] }}:{{ getent_passwd[nodered_user][2] }}" user: "{{ getent_passwd[nodered_user][1] }}:{{ getent_passwd[nodered_user][2] }}"
env: env:
TZ: "Asia/Kolkata" TZ: "Asia/Kolkata"
links: networks:
- "{{ mosquitto_container }}:mqtt" - name: "{{ docker_network }}"
- "{{ influx_container }}:influx"
published_ports:
- 127.0.0.1:1880:1880
volumes: volumes:
- "{{ nodered_directory }}:/data" - "{{ nodered_directory }}:/data"
+5 -5
View File
@@ -1,5 +1,5 @@
--- ---
host_directory: /var/lib host_directory: /var/lib/iot/
user: 'www-data' user: 'www-data'
mosquitto_container: mosquitto mosquitto_container: mosquitto
@@ -12,9 +12,9 @@ nodered_image: nodered/node-red:latest
nodered_directory: "{{ host_directory }}/nodered" nodered_directory: "{{ host_directory }}/nodered"
nodered_user: "{{ user }}" nodered_user: "{{ user }}"
influx_container: influxtestplay influx_container: influx
influx_image: influxdb:latest influx_image: influxdb:latest
influx_directory: "{{ host_directory }}/influxtestplaydir" influx_directory: "{{ host_directory }}/influx"
influx_user: "{{ user }}" influx_user: "{{ user }}"
grafana_container: grafana grafana_container: grafana
@@ -22,6 +22,6 @@ grafana_image: grafana/grafana-enterprise:latest
grafana_directory: "{{ host_directory }}/grafana" grafana_directory: "{{ host_directory }}/grafana"
grafana_user: "{{ user }}" grafana_user: "{{ user }}"
http_host: "iot.tanshu.com" host: iot.tanshu.com
http_conf: "iot.tanshu.com.conf"
docker_network: iot_net