IOT Playbook updated with docker networks and caddy.
This commit is contained in:
1 parent
7c2a66540f
commit
3ff953acdb
13 files changed
+73
-62
No files matched your search
+6
-5
@@ -6,8 +6,9 @@
|
||||
- vars/default.yml
|
||||
|
||||
roles:
|
||||
# - mosquitto
|
||||
# - influxdb
|
||||
# - nodered
|
||||
# - grafana
|
||||
- nginx
|
||||
- network
|
||||
- mosquitto
|
||||
- influxdb
|
||||
- nodered
|
||||
- grafana
|
||||
- caddy
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
caddy_container: caddy
|
||||
caddyfile_path: /var/lib/caddy/conf/Caddyfile
|
||||
snippet_block: |
|
||||
{{ host }} {
|
||||
reverse_proxy {{ grafana_container }}:3000
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
# Handlers for Nginx role
|
||||
- name: Restart caddy container
|
||||
docker_container:
|
||||
name: "{{ caddy_container }}"
|
||||
state: started
|
||||
restart: true
|
||||
@@ -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
|
||||
@@ -27,15 +27,13 @@
|
||||
restart_policy: "unless-stopped"
|
||||
user: "{{ getent_passwd[grafana_user][1] }}:{{ getent_passwd[grafana_user][2] }}"
|
||||
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_AUTH_ANONYMOUS_ENABLED: "true"
|
||||
GF_AUTH_ANONYMOUS_ORG_NAME: "Public"
|
||||
GF_AUTH_ANONYMOUS_ORG_ROLE: "Viewer"
|
||||
GF_AUTH_ANONYMOUS_HIDE_VERSION: "true"
|
||||
links:
|
||||
- "{{ influx_container }}:influx"
|
||||
published_ports:
|
||||
- 127.0.0.1:3005:3000
|
||||
networks:
|
||||
- name: "{{ docker_network }}"
|
||||
volumes:
|
||||
- "{{ grafana_directory }}:/var/lib/grafana"
|
||||
@@ -42,8 +42,10 @@
|
||||
state: started
|
||||
restart_policy: "unless-stopped"
|
||||
user: "{{ getent_passwd[influx_user][1] }}:{{ getent_passwd[influx_user][2] }}"
|
||||
published_ports:
|
||||
- 127.0.0.1:8088:8086
|
||||
networks:
|
||||
- name: "{{ docker_network }}"
|
||||
aliases:
|
||||
- influx
|
||||
volumes:
|
||||
- "{{ influx_directory }}/data:/var/lib/influxdb2"
|
||||
- "{{ influx_directory }}/config:/etc/influxdb2"
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
owner: 1883 # "{{ mosquitto_user }}"
|
||||
mode: 0646
|
||||
|
||||
# - name: Check if Mosquitto passwd file exists
|
||||
# stat: path="{{ mosquitto_directory }}/config/passwd"
|
||||
# register: status
|
||||
|
||||
- name: Ensure Mosquitto passwd file exists
|
||||
template:
|
||||
src: "files/passwd"
|
||||
@@ -47,9 +43,6 @@
|
||||
owner: 1883 # "{{ mosquitto_user }}"
|
||||
mode: 0646
|
||||
|
||||
- name: Encrypt the docker file
|
||||
command: docker exec -i mosquitto mosquitto_passwd -U /mosquitto/config/passwd
|
||||
|
||||
- name: Ensure Mosquitto Log Directory exists
|
||||
file:
|
||||
path: "{{ mosquitto_directory }}/log"
|
||||
@@ -73,10 +66,17 @@
|
||||
state: started
|
||||
restart_policy: "unless-stopped"
|
||||
# user: 0:0 # "{{ getent_passwd[mosquitto_user][1] }}:{{ getent_passwd[mosquitto_user][2] }}"
|
||||
networks:
|
||||
- name: "{{ docker_network }}"
|
||||
aliases:
|
||||
- mqtt
|
||||
published_ports:
|
||||
- 127.0.0.1:9001:9001
|
||||
- 1883:1883
|
||||
volumes:
|
||||
- "{{ mosquitto_directory }}/config:/mosquitto/config"
|
||||
- "{{ mosquitto_directory }}/data:/mosquitto/data"
|
||||
- "{{ mosquitto_directory }}/log:/mosquitto/log"
|
||||
|
||||
- name: Encrypt the docker file
|
||||
command: docker exec -i mosquitto mosquitto_passwd -U /mosquitto/config/passwd
|
||||
|
||||
@@ -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
|
||||
@@ -1,2 +0,0 @@
|
||||
---
|
||||
# Default variables for Nginx role
|
||||
@@ -1,6 +0,0 @@
|
||||
---
|
||||
# Handlers for Nginx role
|
||||
- name: Reload Nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
@@ -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
|
||||
@@ -28,10 +28,7 @@
|
||||
user: "{{ getent_passwd[nodered_user][1] }}:{{ getent_passwd[nodered_user][2] }}"
|
||||
env:
|
||||
TZ: "Asia/Kolkata"
|
||||
links:
|
||||
- "{{ mosquitto_container }}:mqtt"
|
||||
- "{{ influx_container }}:influx"
|
||||
published_ports:
|
||||
- 127.0.0.1:1880:1880
|
||||
networks:
|
||||
- name: "{{ docker_network }}"
|
||||
volumes:
|
||||
- "{{ nodered_directory }}:/data"
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
host_directory: /var/lib
|
||||
host_directory: /var/lib/iot/
|
||||
user: 'www-data'
|
||||
|
||||
mosquitto_container: mosquitto
|
||||
@@ -12,9 +12,9 @@ nodered_image: nodered/node-red:latest
|
||||
nodered_directory: "{{ host_directory }}/nodered"
|
||||
nodered_user: "{{ user }}"
|
||||
|
||||
influx_container: influxtestplay
|
||||
influx_container: influx
|
||||
influx_image: influxdb:latest
|
||||
influx_directory: "{{ host_directory }}/influxtestplaydir"
|
||||
influx_directory: "{{ host_directory }}/influx"
|
||||
influx_user: "{{ user }}"
|
||||
|
||||
grafana_container: grafana
|
||||
@@ -22,6 +22,6 @@ grafana_image: grafana/grafana-enterprise:latest
|
||||
grafana_directory: "{{ host_directory }}/grafana"
|
||||
grafana_user: "{{ user }}"
|
||||
|
||||
http_host: "iot.tanshu.com"
|
||||
http_conf: "iot.tanshu.com.conf"
|
||||
host: iot.tanshu.com
|
||||
|
||||
docker_network: iot_net
|
||||
Reference in new issue
Block a user