mirror of
https://github.com/iiab/iiab.git
synced 2025-02-13 11:42:08 +00:00
157 lines
5.5 KiB
YAML
157 lines
5.5 KiB
YAML
- name: Unmask the Access Point 'hostapd' service
|
|
systemd:
|
|
name: hostapd
|
|
enabled: no
|
|
masked: no
|
|
|
|
- name: Disable hostapd when not using ap0 and wifi gateway present, or no WiFi hardware present
|
|
set_fact:
|
|
hostapd_enabled: False
|
|
when: (not wifi_up_down and discovered_wireless_iface == iiab_wan_iface) or discovered_wireless_iface == "none"
|
|
|
|
- name: Detect current Wifi channel
|
|
shell: iw {{ discovered_wireless_iface }} info | grep channel | cut -d' ' -f2
|
|
register: current_host_channel
|
|
when: discovered_wireless_iface != "none"
|
|
|
|
- name: Setting WiFi channel to {{ current_host_channel.stdout }}
|
|
set_fact:
|
|
host_channel: "{{ current_host_channel.stdout }}"
|
|
when: current_host_channel.stdout is defined and current_host_channel.stdout != "" and current_host_channel.stdout|int <= 13
|
|
|
|
- name: Create /etc/hostapd/hostapd.conf and backup .iiab from template
|
|
template:
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
with_items:
|
|
- { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf' }
|
|
- { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf.iiab' }
|
|
when: discovered_wireless_iface != "none"
|
|
|
|
- name: Generate new random mac address for ap0
|
|
shell: tr -dc A-F0-9 < /dev/urandom | head -c 10 | sed -r 's/(..)/\1:/g;s/:$//;s/^/02:/'
|
|
register: ap0_mac
|
|
|
|
- name: Setting ap0 mac address for use in hostapd service file
|
|
set_fact:
|
|
ap0_mac_addr: "{{ ap0_mac.stdout }}"
|
|
|
|
- name: Use custom 'hostapd' systemd service unit file using ap0 when wifi_up_down
|
|
template:
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
with_items:
|
|
- { src: 'hostapd/hostapd.service.j2', dest: '/etc/systemd/system/hostapd.service' }
|
|
- { src: 'hostapd/clone-wifi.service.j2', dest: '/etc/systemd/system/clone-wifi.service' }
|
|
- { src: 'hostapd/wifi-test.service.j2', dest: '/etc/systemd/system/wifi-test.service' }
|
|
- { src: 'hostapd/test-wifi', dest: '/sbin/test-wifi' }
|
|
when: discovered_wireless_iface != "none" and wifi_up_down
|
|
|
|
- name: Use custom 'hostapd' systemd service unit file for {{ discovered_wireless_iface }} when not wifi_up_down
|
|
template:
|
|
src: hostapd/hostapd.legacy.j2
|
|
dest: /etc/systemd/system/hostapd.service
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
when: discovered_wireless_iface != "none" and not wifi_up_down
|
|
|
|
- name: Create /usr/bin/iiab-hotspot-on from template
|
|
template:
|
|
src: network/iiab-hotspot-on
|
|
dest: /usr/bin/iiab-hotspot-on
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
|
|
- name: Create /usr/bin/iiab-hotspot-off from template
|
|
template:
|
|
src: network/iiab-hotspot-off
|
|
dest: /usr/bin/iiab-hotspot-off
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
|
|
- name: Create dhcpcd hook for hostapd and ap0 when wifi_up_down True
|
|
template:
|
|
src: hostapd/50-hostapd
|
|
dest: /lib/dhcpcd/dhcpcd-hooks/50-hostapd
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
when: is_raspbian and wifi_up_down
|
|
|
|
- name: Remove dhcpcd hook for hostapd if WiFi is not split using ap0
|
|
file:
|
|
path: /lib/dhcpcd/dhcpcd-hooks/50-hostapd
|
|
state: absent
|
|
when: is_raspbian and not wifi_up_down
|
|
|
|
- name: Create networkd-dispatcher diagnosic hook for recording network events
|
|
template:
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
with_items:
|
|
- { src: 'hostapd/00-iiab-debug', dest: '/etc/networkd-dispatcher/carrier.d/00-iiab-debug' }
|
|
- { src: 'hostapd/00-iiab-debug', dest: '/etc/networkd-dispatcher/degraded.d/00-iiab-debug' }
|
|
- { src: 'hostapd/00-iiab-debug', dest: '/etc/networkd-dispatcher/dormant.d/00-iiab-debug' }
|
|
- { src: 'hostapd/00-iiab-debug', dest: '/etc/networkd-dispatcher/no-carrier.d/00-iiab-debug' }
|
|
- { src: 'hostapd/00-iiab-debug', dest: '/etc/networkd-dispatcher/off.d/00-iiab-debug' }
|
|
- { src: 'hostapd/00-iiab-debug', dest: '/etc/networkd-dispatcher/routable.d/00-iiab-debug' }
|
|
when: systemd_networkd_active and discovered_wireless_iface != "none"
|
|
|
|
- name: Create networkd-dispatcher hook for hostapd wifi_up_down True
|
|
template:
|
|
owner: root
|
|
group: root
|
|
mode: 0755
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
with_items:
|
|
- { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' }
|
|
- { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' }
|
|
- { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' }
|
|
when: systemd_networkd_active and discovered_wireless_iface != "none" and wifi_up_down
|
|
|
|
- name: Remove networkd-dispatcher hook wifi_up_down False
|
|
file:
|
|
path: "{{ item.dest }}"
|
|
state: absent
|
|
with_items:
|
|
- { dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' }
|
|
- { dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' }
|
|
- { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' }
|
|
when: systemd_networkd_active and discovered_wireless_iface != "none" and not wifi_up_down
|
|
|
|
- name: Enable the Access Point 'hostapd' service
|
|
systemd:
|
|
name: hostapd
|
|
enabled: yes
|
|
when: hostapd_enabled and not wifi_up_down
|
|
|
|
- name: Enable the Access Point 'hostapd' service
|
|
systemd:
|
|
name: "{{ item }}"
|
|
masked: no
|
|
enabled: yes
|
|
with_items:
|
|
- hostapd.service
|
|
- clone-wifi.service
|
|
- wifi-test.service
|
|
when: hostapd_enabled and wifi_up_down
|
|
|
|
- name: Record HOSTAPD_ENABLED to {{ iiab_env_file }}
|
|
lineinfile:
|
|
path: "{{ iiab_env_file }}"
|
|
regexp: '^HOSTAPD_ENABLED=*'
|
|
line: 'HOSTAPD_ENABLED={{ hostapd_enabled }}'
|
|
state: present
|