ham-hotspot/ansible/playbook.yml
2025-04-25 22:37:07 -05:00

185 lines
4.5 KiB
YAML

---
- name: Ham Hotspot Bootstrap
hosts: localhost
become: yes
connection: local
vars_files:
- ../config/desired_state.yml
handlers:
- import_tasks: ../handlers/main.yml
tasks:
- name: Install base apt packages
apt:
name:
- ax25-tools
- ax25-apps
- libax25
- dnsmasq
- hostapd
- python3-flask
- build-essential
- cmake
- git
- alsa-utils
- libasound2-dev
- libudev-dev
- avahi-daemon
- libavahi-client-dev
state: present
update_cache: yes
- name: Clone Direwolf from GitHub
git:
repo: 'https://github.com/wb2osz/direwolf.git'
dest: /usr/local/src/direwolf
update: no
- name: Build Direwolf
shell: |
mkdir -p /usr/local/src/direwolf/build
cd /usr/local/src/direwolf/build
cmake ..
make -j4
args:
chdir: /usr/local/src/direwolf
creates: /usr/local/src/direwolf/build/direwolf
- name: Install Direwolf
shell: |
cd /usr/local/src/direwolf/build
make install
args:
chdir: /usr/local/src/direwolf/build
creates: /usr/local/bin/direwolf
- name: Copy systemd service templates
copy:
src: ../systemd/
dest: /lib/systemd/system/
mode: '0644'
owner: root
group: root
- name: Create /etc/ham-hotspot directory
file:
path: /etc/ham-hotspot
state: directory
mode: '0755'
owner: root
group: root
- name: Deploy Direwolf configuration
template:
src: ../templates/direwolf.conf.j2
dest: /etc/ham-hotspot/direwolf-{{ radio.port_name }}.conf
mode: '0644'
- name: Deploy hostapd configuration
template:
src: ../templates/hostapd.conf.j2
dest: /etc/hostapd/hostapd.conf
mode: '0644'
notify: Restart hostapd
- name: Deploy dnsmasq configuration
template:
src: ../templates/dnsmasq.conf.j2
dest: /etc/dnsmasq.d/ham-hotspot.conf
mode: '0644'
notify: Restart dnsmasq
- name: Deploy axports configuration
template:
src: ../templates/axports.j2
dest: /etc/ax25/axports
mode: '0644'
- name: Enable IP forwarding
copy:
dest: /etc/sysctl.d/ham-hotspot.conf
content: |
net.ipv4.ip_forward=1
mode: '0644'
- name: Unmask hostapd service
systemd:
name: hostapd
masked: no
- name: Ensure /etc/wpa_supplicant/wpa_supplicant.conf exists
file:
path: /etc/wpa_supplicant/wpa_supplicant.conf
state: touch
owner: root
group: root
mode: '0644'
- name: Ensure Wi-Fi country is set in wpa_supplicant.conf
blockinfile:
path: /etc/wpa_supplicant/wpa_supplicant.conf
marker: "# {mark} ANSIBLE MANAGED BLOCK - Wi-Fi Country Setting"
block: |
country={{ wifi.country }}
when: ansible_facts['distribution'] in ['Debian', 'Raspbian']
- name: Install unblock-wlan.service
copy:
src: ../systemd/unblock-wlan.service
dest: /etc/systemd/system/unblock-wlan.service
mode: '0644'
owner: root
group: root
- name: Reload systemd daemon
systemd:
daemon_reload: yes
- name: Enable and start unblock-wlan.service
systemd:
name: unblock-wlan.service
enabled: yes
state: started
- name: Enable and start Direwolf instance
systemd:
name: direwolf@radio0.service
enabled: yes
state: started
- name: Enable and start KISS TNC instance
systemd:
name: kisstnc@radio0.service
enabled: yes
state: started
- name: Enable and start AX.25 daemon
systemd:
name: ax25d.service
enabled: yes
state: started
- name: Assign static IP to ax0
shell: |
ip addr add {{ radio.ip_address }}/24 dev ax0 || true
ip link set ax0 up
- name: Enable and start hostapd
systemd:
name: hostapd.service
enabled: yes
state: started
- name: Assign static IP to wlan0
shell: |
ip addr add {{ network.lan_gateway }}/24 dev wlan0 || true
ip link set wlan0 up
- name: Enable and start dnsmasq
systemd:
name: dnsmasq.service
enabled: yes
state: started