/
/
/
Ansible role that deploys my edge device with connectivity containers. Currently it deploys a thread border router via the zbt-1 dongle by Home Assistant, a zigbee2MQTT interface using the Sonoff zigbee dongle and a DSMR reader with a generic P1 to USB converter.
1---
2
3
4- name: Create OTBR compose directory
5 ansible.builtin.file:
6 path: "{{ otbr_compose_dir }}"
7 state: directory
8 owner: "ansible"
9 group: "users"
10 mode: "0775"
11
12- name: Create OTBR data directory
13 ansible.builtin.file:
14 path: "{{ otbr_compose_dir }}/data/otbr"
15 state: directory
16 owner: "ansible"
17 group: "users"
18 mode: "0775"
19
20- name: Render OTBR compose
21 ansible.builtin.template:
22 src: otbr-docker-compose.yml.j2
23 dest: "{{ otbr_compose_dir }}/docker-compose.yml"
24 owner: "ansible"
25 group: "users"
26 mode: "0664"
27
28- name: Render OTBR environment file
29 ansible.builtin.template:
30 src: otbr.env.j2
31 dest: "{{ otbr_compose_dir }}/.env"
32 owner: "ansible"
33 group: "users"
34 mode: "0664"
35
36- name: Stop and remove existing OTBR containers
37 community.docker.docker_compose_v2:
38 project_src: "{{ otbr_compose_dir }}"
39 state: absent
40 ignore_errors: yes
41
42- name: Bring up OTBR
43 community.docker.docker_compose_v2:
44 project_src: "{{ otbr_compose_dir }}"
45 state: present
46
47# Optional: pre-provision dataset if you chose dataset.active=true
48- name: Initialize Thread dataset (optional)
49 when: otbr_dataset_active | bool
50 ansible.builtin.shell: |
51 docker exec otbr sh -c '
52 ot-ctl dataset init new &&
53 ot-ctl dataset networkname "{{ otbr_dataset_network_name }}" &&
54 ot-ctl dataset panid {{ otbr_dataset_panid }} &&
55 ot-ctl dataset extpanid {{ otbr_dataset_extpanid }} &&
56 ot-ctl dataset channel {{ otbr_dataset_channel }} &&
57 ot-ctl dataset networkkey {{ otbr_dataset_network_key }} &&
58 ot-ctl dataset commit active &&
59 ot-ctl ifconfig up &&
60 ot-ctl thread start
61 '
62 changed_when: false
63
64