netz39-infra-ansible/radon.yml

88 lines
2.2 KiB
YAML
Raw Normal View History

2022-06-24 17:01:50 +02:00
---
- hosts: radon.n39.eu
become: true
vars:
ansible_python_interpreter: /usr/bin/python3
data_dir: "/srv/data"
2022-06-25 18:27:53 +02:00
mosquitto_image: eclipse-mosquitto:2.0.14
mosquitto_data: "{{ data_dir }}/mosquitto"
2022-06-25 18:15:52 +02:00
2022-07-29 15:17:51 +02:00
nodered_image: nodered/node-red:3.0.1-1-18
nodered_data: "{{ data_dir }}/nodered"
2022-06-24 17:01:50 +02:00
roles:
- role: docker_setup
vars:
docker_data_root: "/srv/docker"
tasks:
2022-06-25 18:15:52 +02:00
- name: Ensure the mosquitto directories exist
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ mosquitto_data }}/config"
- "{{ mosquitto_data }}/data"
- "{{ mosquitto_data }}/log"
- name: Make sure mosquitto config is there
template:
src: "templates/mosquitto.conf.j2"
dest: "{{ mosquitto_data }}/config/mosquitto.conf"
2022-06-25 18:23:04 +02:00
notify: restart mosquitto
2022-06-25 18:15:52 +02:00
- name: Ensure mosquitto is running
docker_container:
name: mosquitto
image: "{{ mosquitto_image }}"
pull: true
state: started
ports:
- 1883:1883
- 9001:9001
volumes:
- "{{ mosquitto_data }}/config:/mosquitto/config"
- "{{ mosquitto_data }}/data:/mosquitto/data"
- "{{ mosquitto_data }}/log:/mosquitto/log"
detach: yes
keep_volumes: yes
restart_policy: unless-stopped
2022-06-24 17:01:50 +02:00
2022-07-29 15:17:51 +02:00
- name: Check if nodered data dir exists
ansible.builtin.stat:
path: "{{ data_dir }}/nodered"
register: nodered_dir
- name: Fail if nodered data dir does not exist
ansible.builtin.fail:
msg: "Nodered data dir is missing, please restore from the backup!"
when: not nodered_dir.stat.exists
- name: Ensure nodered is running
docker_container:
name: nodered
image: "{{ nodered_image }}"
pull: true
state: started
env:
TZ: Europe/Berlin
NODE_RED_ENABLE_PROJECTS: "true"
ports:
# - 127.0.0.1:9002:1880
- 9002:1880
volumes:
- "{{ nodered_data }}/data:/data"
detach: yes
keep_volumes: yes
restart_policy: unless-stopped
2022-06-24 17:01:50 +02:00
handlers:
2022-06-25 18:15:52 +02:00
- name: restart mosquitto
docker_container:
name: mosquitto
state: started
restart: yes