Add Ansible playbooks for MeshCore monitoring node deployment
Roles: base (apt, tailscale, motd), meshcore_cli (pipx), meshcore_capture (agessaman/meshcore-packet-capture + .env.local template), scripts (voltage, bandwidth). Host vars contain per-device serial ports; group vars hold shared MQTT broker config. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
---
|
||||
- name: Install base packages
|
||||
apt:
|
||||
name:
|
||||
- screen
|
||||
- pipx
|
||||
- vnstat
|
||||
- git
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Set MOTD
|
||||
template:
|
||||
src: motd.j2
|
||||
dest: /etc/motd
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
become: true
|
||||
|
||||
- name: Add Tailscale apt signing key
|
||||
get_url:
|
||||
url: https://pkgs.tailscale.com/stable/debian/bookworm.nosetup.sh
|
||||
dest: /tmp/tailscale-setup.sh
|
||||
mode: "0755"
|
||||
when: tailscale_auth_key != ""
|
||||
|
||||
- name: Run Tailscale install script
|
||||
shell: sh /tmp/tailscale-setup.sh
|
||||
args:
|
||||
creates: /usr/bin/tailscale
|
||||
become: true
|
||||
when: tailscale_auth_key != ""
|
||||
|
||||
- name: Enable and start tailscaled
|
||||
systemd:
|
||||
name: tailscaled
|
||||
enabled: true
|
||||
state: started
|
||||
become: true
|
||||
when: tailscale_auth_key != ""
|
||||
|
||||
- name: Authenticate Tailscale
|
||||
shell: tailscale up --authkey {{ tailscale_auth_key }}
|
||||
become: true
|
||||
when: tailscale_auth_key != ""
|
||||
no_log: true
|
||||
@@ -0,0 +1,8 @@
|
||||
__ __ __
|
||||
____/ /___ / /_____ ___ ___ _____/ /_
|
||||
/ __ / __ \/ __/ __ `__ \/ _ \/ ___/ __ \
|
||||
/ /_/ / /_/ / /_/ / / / / / __(__ ) / / /
|
||||
\__,_/\____/\__/_/ /_/ /_/\___/____/_/ /_/
|
||||
|
||||
{{ inventory_hostname }} :: {{ meshcore_description }}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: restart meshcore-capture
|
||||
systemd:
|
||||
name: meshcore-capture
|
||||
state: restarted
|
||||
become: true
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
- name: Run meshcore-packet-capture install script
|
||||
shell: |
|
||||
bash <(curl -fsSL https://raw.githubusercontent.com/agessaman/meshcore-packet-capture/main/install.sh)
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: /etc/systemd/system/meshcore-capture.service
|
||||
become: false
|
||||
|
||||
- name: Write .env.local config
|
||||
template:
|
||||
src: env.local.j2
|
||||
dest: "{{ ansible_env.HOME }}/.meshcore-packet-capture/.env.local"
|
||||
mode: "0640"
|
||||
become: false
|
||||
notify: restart meshcore-capture
|
||||
|
||||
- name: Enable and start meshcore-capture service
|
||||
systemd:
|
||||
name: meshcore-capture
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
||||
become: true
|
||||
|
||||
- name: Deploy meshcore-capture-update script
|
||||
copy:
|
||||
content: "#!/usr/bin/env bash\nbash <(curl -fsSL https://raw.githubusercontent.com/agessaman/meshcore-packet-capture/main/install.sh)\n"
|
||||
dest: "{{ ansible_env.HOME }}/meshcore-capture-update.sh"
|
||||
mode: "0755"
|
||||
become: false
|
||||
|
||||
- name: Deploy meshcore-capture-logs script
|
||||
copy:
|
||||
content: "#!/usr/bin/env bash\nsudo journalctl -u meshcore-capture -f\n"
|
||||
dest: "{{ ansible_env.HOME }}/meshcore-capture-logs.sh"
|
||||
mode: "0755"
|
||||
become: false
|
||||
@@ -0,0 +1,77 @@
|
||||
# MeshCore Packet Capture Configuration
|
||||
# Managed by Ansible - local changes will be overwritten on next playbook run
|
||||
|
||||
# Update source
|
||||
PACKETCAPTURE_UPDATE_REPO={{ packetcapture_update_repo }}
|
||||
PACKETCAPTURE_UPDATE_BRANCH={{ packetcapture_update_branch }}
|
||||
|
||||
# Connection Configuration
|
||||
PACKETCAPTURE_CONNECTION_TYPE=serial
|
||||
PACKETCAPTURE_SERIAL_PORTS={{ serial_port }}
|
||||
|
||||
# Location Code
|
||||
PACKETCAPTURE_IATA={{ packetcapture_iata }}
|
||||
|
||||
# Advert Settings
|
||||
PACKETCAPTURE_ADVERT_INTERVAL_HOURS={{ packetcapture_advert_interval_hours }}
|
||||
|
||||
# Logging Settings
|
||||
PACKETCAPTURE_LOG_LEVEL={{ packetcapture_log_level }}
|
||||
PACKETCAPTURE_OWNER_PUBLIC_KEY={{ packetcapture_owner_public_key }}
|
||||
PACKETCAPTURE_OWNER_EMAIL={{ packetcapture_owner_email }}
|
||||
|
||||
# MQTT Broker 1 - LetsMesh.net Packet Analyzer (US)
|
||||
PACKETCAPTURE_MQTT1_ENABLED=true
|
||||
PACKETCAPTURE_MQTT1_SERVER=mqtt-us-v1.letsmesh.net
|
||||
PACKETCAPTURE_MQTT1_PORT=443
|
||||
PACKETCAPTURE_MQTT1_TRANSPORT=websockets
|
||||
PACKETCAPTURE_MQTT1_USE_TLS=true
|
||||
PACKETCAPTURE_MQTT1_USE_AUTH_TOKEN=true
|
||||
PACKETCAPTURE_MQTT1_TOKEN_AUDIENCE=mqtt-us-v1.letsmesh.net
|
||||
PACKETCAPTURE_MQTT1_KEEPALIVE=120
|
||||
PACKETCAPTURE_MQTT1_TOPIC_STATUS=meshcore/{IATA}/{PUBLIC_KEY}/status
|
||||
PACKETCAPTURE_MQTT1_TOPIC_PACKETS=meshcore/{IATA}/{PUBLIC_KEY}/packets
|
||||
|
||||
# MQTT Broker 2 - LetsMesh.net Packet Analyzer (EU)
|
||||
PACKETCAPTURE_MQTT2_ENABLED=true
|
||||
PACKETCAPTURE_MQTT2_SERVER=mqtt-eu-v1.letsmesh.net
|
||||
PACKETCAPTURE_MQTT2_PORT=443
|
||||
PACKETCAPTURE_MQTT2_TRANSPORT=websockets
|
||||
PACKETCAPTURE_MQTT2_USE_TLS=true
|
||||
PACKETCAPTURE_MQTT2_USE_AUTH_TOKEN=true
|
||||
PACKETCAPTURE_MQTT2_TOKEN_AUDIENCE=mqtt-eu-v1.letsmesh.net
|
||||
PACKETCAPTURE_MQTT2_KEEPALIVE=120
|
||||
PACKETCAPTURE_MQTT2_TOPIC_STATUS=meshcore/{IATA}/{PUBLIC_KEY}/status
|
||||
PACKETCAPTURE_MQTT2_TOPIC_PACKETS=meshcore/{IATA}/{PUBLIC_KEY}/packets
|
||||
|
||||
# MQTT Broker 3 - MeshRank
|
||||
PACKETCAPTURE_MQTT3_ENABLED=true
|
||||
PACKETCAPTURE_MQTT3_SERVER=meshrank.net
|
||||
PACKETCAPTURE_MQTT3_PORT=8883
|
||||
PACKETCAPTURE_MQTT3_TRANSPORT=tcp
|
||||
PACKETCAPTURE_MQTT3_USE_TLS=true
|
||||
PACKETCAPTURE_MQTT3_TLS_VERIFY=true
|
||||
PACKETCAPTURE_MQTT3_TOPIC_PACKETS=meshrank/uplink/{{ mqtt_meshrank_token }}/{PUBLIC_KEY}/packets
|
||||
PACKETCAPTURE_MQTT3_TOPIC_STATUS=meshrank/uplink/{{ mqtt_meshrank_token }}/{PUBLIC_KEY}/status
|
||||
|
||||
# MQTT Broker 4 - UKMesh
|
||||
PACKETCAPTURE_MQTT4_ENABLED=true
|
||||
PACKETCAPTURE_MQTT4_SERVER=mqtt.ukmesh.com
|
||||
PACKETCAPTURE_MQTT4_PORT=443
|
||||
PACKETCAPTURE_MQTT4_TRANSPORT=websockets
|
||||
PACKETCAPTURE_MQTT4_USE_TLS=true
|
||||
PACKETCAPTURE_MQTT4_USERNAME={{ mqtt_ukmesh_username }}
|
||||
PACKETCAPTURE_MQTT4_PASSWORD={{ mqtt_ukmesh_password }}
|
||||
PACKETCAPTURE_MQTT4_TOPIC_STATUS=meshcore/{IATA}/{PUBLIC_KEY}/status
|
||||
PACKETCAPTURE_MQTT4_TOPIC_PACKETS=meshcore/{IATA}/{PUBLIC_KEY}/packets
|
||||
|
||||
# MQTT Broker 5 - MeshMapper
|
||||
PACKETCAPTURE_MQTT5_ENABLED=true
|
||||
PACKETCAPTURE_MQTT5_SERVER=mqtt.meshmapper.cc
|
||||
PACKETCAPTURE_MQTT5_PORT=443
|
||||
PACKETCAPTURE_MQTT5_TRANSPORT=websockets
|
||||
PACKETCAPTURE_MQTT5_USE_TLS=true
|
||||
PACKETCAPTURE_MQTT5_USE_AUTH_TOKEN=true
|
||||
PACKETCAPTURE_MQTT5_TOKEN_AUDIENCE=mqtt.meshmapper.cc
|
||||
PACKETCAPTURE_MQTT5_TOPIC_STATUS=meshcore/{IATA}/{PUBLIC_KEY}/status
|
||||
PACKETCAPTURE_MQTT5_TOPIC_PACKETS=meshcore/{IATA}/{PUBLIC_KEY}/packets
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Ensure pipx path is configured
|
||||
shell: pipx ensurepath
|
||||
args:
|
||||
executable: /bin/bash
|
||||
become: false
|
||||
register: pipx_ensurepath
|
||||
changed_when: "'already' not in pipx_ensurepath.stdout"
|
||||
|
||||
- name: Install meshcore-cli via pipx
|
||||
shell: pipx install meshcore-cli
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: "{{ ansible_env.HOME }}/.local/bin/meshcore-cli"
|
||||
become: false
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
vnstat
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT=$(basename "$0")
|
||||
|
||||
# fetch status
|
||||
STATUS=$(vcgencmd get_throttled | cut -d "=" -f 2)
|
||||
|
||||
# decode - https://www.raspberrypi.com/documentation/computers/os.html#get_throttled
|
||||
echo "vcgencmd get_throttled ($STATUS)"
|
||||
IFS=","
|
||||
for BITMAP in \
|
||||
00,"currently under-voltage" \
|
||||
01,"ARM frequency currently capped" \
|
||||
02,"currently throttled" \
|
||||
03,"soft temperature limit reached" \
|
||||
16,"under-voltage has occurred since last reboot" \
|
||||
17,"ARM frequency capping has occurred since last reboot" \
|
||||
18,"throttling has occurred since last reboot" \
|
||||
19,"soft temperature reached since last reboot"
|
||||
do set -- $BITMAP
|
||||
if [ $(($STATUS & 1 << $1)) -ne 0 ] ; then echo " $2" ; fi
|
||||
done
|
||||
|
||||
echo "vcgencmd measure_volts:"
|
||||
for S in core sdram_c sdram_i sdram_p ; do printf '%9s %s\n' "$S" "$(vcgencmd measure_volts $S)" ; done
|
||||
|
||||
echo "Temperature: $(vcgencmd measure_temp)"
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Deploy voltage.sh
|
||||
copy:
|
||||
src: voltage.sh
|
||||
dest: "{{ ansible_env.HOME }}/voltage.sh"
|
||||
mode: "0755"
|
||||
become: false
|
||||
|
||||
- name: Deploy bandwidth.sh
|
||||
copy:
|
||||
src: bandwidth.sh
|
||||
dest: "{{ ansible_env.HOME }}/bandwidth.sh"
|
||||
mode: "0755"
|
||||
become: false
|
||||
Reference in New Issue
Block a user