2020-05-01 05:05:35 +00:00
|
|
|
- name: Unmask the Access Point 'hostapd' service
|
|
|
|
systemd:
|
|
|
|
name: hostapd
|
|
|
|
enabled: no
|
|
|
|
masked: no
|
|
|
|
|
2020-05-04 19:32:43 +00:00
|
|
|
- name: Disable hostapd when not using ap0 and wifi gateway present, or no WiFi hardware present
|
2019-08-15 11:09:22 +00:00
|
|
|
set_fact:
|
|
|
|
hostapd_enabled: False
|
2020-05-03 19:00:20 +00:00
|
|
|
when: (not wifi_up_down and discovered_wireless_iface == iiab_wan_iface) or discovered_wireless_iface == "none"
|
2019-08-15 11:09:22 +00:00
|
|
|
|
2020-04-03 10:24:22 +00:00
|
|
|
- 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"
|
|
|
|
|
2020-05-01 00:31:51 +00:00
|
|
|
- name: Setting WiFi channel to {{ current_host_channel.stdout }}
|
2020-04-03 10:24:22 +00:00
|
|
|
set_fact:
|
|
|
|
host_channel: "{{ current_host_channel.stdout }}"
|
2020-05-01 00:31:51 +00:00
|
|
|
when: current_host_channel.stdout is defined and current_host_channel.stdout != "" and current_host_channel.stdout|int <= 13
|
2020-04-03 10:24:22 +00:00
|
|
|
|
2020-04-22 17:38:49 +00:00
|
|
|
- name: Create /etc/hostapd/hostapd.conf and backup .iiab from template
|
2017-12-29 00:08:13 +00:00
|
|
|
template:
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2020-04-22 17:38:49 +00:00
|
|
|
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' }
|
2019-08-15 13:39:54 +00:00
|
|
|
when: discovered_wireless_iface != "none"
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-03-25 02:41:20 +00:00
|
|
|
- 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 }}"
|
|
|
|
|
2020-04-22 20:56:57 +00:00
|
|
|
- name: Use custom 'hostapd' systemd service unit file using ap0
|
2017-12-29 00:08:13 +00:00
|
|
|
template:
|
|
|
|
owner: root
|
|
|
|
group: root
|
2020-04-22 17:38:49 +00:00
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "{{ item.dest }}"
|
2020-04-22 20:56:57 +00:00
|
|
|
mode: "{{ item.mode }}"
|
2020-04-22 17:38:49 +00:00
|
|
|
with_items:
|
2020-04-22 20:56:57 +00:00
|
|
|
- { src: 'hostapd/hostapd.service.j2', dest: '/etc/systemd/system/hostapd.service', mode: '0644' }
|
|
|
|
- { src: 'hostapd/clone-wifi.service.j2', dest: '/etc/systemd/system/clone-wifi.service', mode: '0644' }
|
|
|
|
- { src: 'hostapd/wifi-test.service.j2', dest: '/etc/systemd/system/wifi-test.service', mode: '0644'}
|
|
|
|
- { src: 'hostapd/test-wifi', dest: '/sbin/test-wifi', mode: '0755' }
|
|
|
|
when: discovered_wireless_iface != "none"
|
2020-04-13 09:50:56 +00:00
|
|
|
|
|
|
|
- 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
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2017-12-28 22:13:22 +00:00
|
|
|
- name: Create /usr/bin/iiab-hotspot-on from template
|
2017-12-29 00:08:13 +00:00
|
|
|
template:
|
|
|
|
src: network/iiab-hotspot-on
|
|
|
|
dest: /usr/bin/iiab-hotspot-on
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
2017-11-19 00:48:13 +00:00
|
|
|
|
2017-12-28 22:13:22 +00:00
|
|
|
- name: Create /usr/bin/iiab-hotspot-off from template
|
2017-12-29 00:08:13 +00:00
|
|
|
template:
|
|
|
|
src: network/iiab-hotspot-off
|
|
|
|
dest: /usr/bin/iiab-hotspot-off
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
2017-11-19 00:48:13 +00:00
|
|
|
|
2020-05-01 05:05:35 +00:00
|
|
|
- name: Create dhcpcd hook for hostapd and ap0 when wifi_up_down True
|
2018-12-03 05:15:22 +00:00
|
|
|
template:
|
|
|
|
src: hostapd/50-hostapd
|
|
|
|
dest: /lib/dhcpcd/dhcpcd-hooks/50-hostapd
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2020-04-10 19:42:26 +00:00
|
|
|
when: is_raspbian and wifi_up_down
|
2018-12-03 05:15:22 +00:00
|
|
|
|
2020-05-01 05:05:35 +00:00
|
|
|
- name: Remove dhcpcd hook for hostapd if WiFi is not split using ap0
|
2020-04-10 22:23:49 +00:00
|
|
|
file:
|
|
|
|
path: /lib/dhcpcd/dhcpcd-hooks/50-hostapd
|
|
|
|
state: absent
|
|
|
|
when: is_raspbian and not wifi_up_down
|
|
|
|
|
2020-10-28 04:49:54 +00:00
|
|
|
- name: Create networkd-dispatcher diagnostic hook for recording network events
|
2020-04-03 06:03:46 +00:00
|
|
|
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"
|
|
|
|
|
2020-05-01 05:05:35 +00:00
|
|
|
- name: Create networkd-dispatcher hook for hostapd wifi_up_down True
|
2020-04-03 06:03:46 +00:00
|
|
|
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' }
|
2020-05-04 16:09:31 +00:00
|
|
|
- { src: 'hostapd/netd-disp2', dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi2' }
|
2020-05-01 00:31:51 +00:00
|
|
|
when: systemd_networkd_active and discovered_wireless_iface != "none" and wifi_up_down
|
2020-04-12 16:53:26 +00:00
|
|
|
|
2020-05-01 05:05:35 +00:00
|
|
|
- name: Remove networkd-dispatcher hook wifi_up_down False
|
2020-04-27 20:48:38 +00:00
|
|
|
file:
|
|
|
|
path: "{{ item.dest }}"
|
|
|
|
state: absent
|
2020-04-12 16:53:26 +00:00
|
|
|
with_items:
|
2020-04-12 18:31:16 +00:00
|
|
|
- { dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' }
|
|
|
|
- { dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' }
|
2020-04-23 15:51:00 +00:00
|
|
|
- { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' }
|
2020-05-04 16:09:31 +00:00
|
|
|
- { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi2' }
|
2020-05-01 05:05:35 +00:00
|
|
|
when: systemd_networkd_active and discovered_wireless_iface != "none" and not wifi_up_down
|
2018-04-07 21:45:04 +00:00
|
|
|
|
|
|
|
- name: Enable the Access Point 'hostapd' service
|
|
|
|
systemd:
|
|
|
|
name: hostapd
|
|
|
|
enabled: yes
|
2020-04-22 17:38:49 +00:00
|
|
|
when: hostapd_enabled and not wifi_up_down
|
|
|
|
|
2020-04-22 20:56:57 +00:00
|
|
|
- name: Disable ap0 related services
|
|
|
|
systemd:
|
|
|
|
name: "{{ item }}"
|
|
|
|
enabled: no
|
2020-05-04 19:39:26 +00:00
|
|
|
daemon_reload: yes
|
2020-04-22 20:56:57 +00:00
|
|
|
with_items:
|
|
|
|
- clone-wifi.service
|
|
|
|
- wifi-test.service
|
|
|
|
when: not wifi_up_down
|
|
|
|
|
|
|
|
- name: Enable the Access Point 'hostapd' and ap0 related services
|
2020-04-22 17:38:49 +00:00
|
|
|
systemd:
|
|
|
|
name: "{{ item }}"
|
|
|
|
enabled: yes
|
2020-05-04 19:39:26 +00:00
|
|
|
daemon_reload: yes
|
2020-04-22 17:38:49 +00:00
|
|
|
with_items:
|
2020-05-04 23:15:04 +00:00
|
|
|
- hostapd.service
|
2020-04-22 17:38:49 +00:00
|
|
|
- clone-wifi.service
|
|
|
|
- wifi-test.service
|
|
|
|
when: hostapd_enabled and wifi_up_down
|
2018-04-09 00:46:31 +00:00
|
|
|
|
2018-10-15 10:41:58 +00:00
|
|
|
- name: Record HOSTAPD_ENABLED to {{ iiab_env_file }}
|
2018-04-09 00:46:31 +00:00
|
|
|
lineinfile:
|
2020-02-04 00:54:04 +00:00
|
|
|
path: "{{ iiab_env_file }}"
|
2018-04-09 00:46:31 +00:00
|
|
|
regexp: '^HOSTAPD_ENABLED=*'
|
|
|
|
line: 'HOSTAPD_ENABLED={{ hostapd_enabled }}'
|
|
|
|
state: present
|