2021-12-17 10:10:31 +00:00
- name : Disable hostapd when not using ap0 and wifi gateway present, or no WiFi hardware present or support not detected
2019-08-15 11:09:22 +00:00
set_fact :
hostapd_enabled : False
2021-12-17 10:10:31 +00:00
when : (not wifi_up_down and discovered_wireless_iface == iiab_wan_iface) or discovered_wireless_iface == "none" or not can_be_ap
2019-08-15 11:09:22 +00:00
2022-07-19 05:49:28 +00:00
- name : Disable the Access Point 'hostapd' service
systemd :
name : hostapd
enabled : no
when : not hostapd_enabled
2023-04-23 21:11:03 +00:00
- name : Detect WiFi country code in use
shell : iw reg get | grep country | grep -v UNSET | awk '{print $2}' | sed "s|:||"
register : REG_DOM
ignore_errors : True
when : wifi_up_down and can_be_ap and has_wifi_gateway is defined
- name : Set Wifi Region country code for hostapd when present
set_fact :
host_country_code : "{{ REG_DOM.stdout }}"
when : REG_DOM.stdout is defined and REG_DOM.stdout | length > 0
2020-04-03 10:24:22 +00:00
- name : Detect current Wifi channel
shell : iw {{ discovered_wireless_iface }} info | grep channel | cut -d' ' -f2
2021-04-30 11:53:07 +00:00
register : current_client_channel
2023-04-23 03:05:01 +00:00
when : wifi_up_down and can_be_ap and has_wifi_gateway is defined
2020-04-03 10:24:22 +00:00
2021-04-30 11:53:07 +00:00
- name : Setting WiFi channel to {{ current_client_channel.stdout }}
2020-04-03 10:24:22 +00:00
set_fact :
2021-04-30 11:53:07 +00:00
host_channel : "{{ current_client_channel.stdout }}"
when : current_client_channel.stdout is defined and current_client_channel.stdout != "" and current_client_channel.stdout|int <= 13
2020-04-03 10:24:22 +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
2022-07-19 05:49:28 +00:00
when : can_be_ap
2020-03-25 02:41:20 +00:00
- name : Setting ap0 mac address for use in hostapd service file
set_fact :
ap0_mac_addr : "{{ ap0_mac.stdout }}"
2022-07-19 05:49:28 +00:00
when : can_be_ap
2020-03-25 02:41:20 +00:00
2021-07-28 02:36:07 +00:00
- name : "Use custom 'hostapd' systemd service unit file using ap0 -- install from template: /etc/systemd/system/hostapd.service, /etc/systemd/system/iiab-clone-wifi.service, /etc/systemd/system/iiab-wifi-test.service, /usr/sbin/iiab-test-wifi"
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' }
2021-07-28 02:36:07 +00:00
- { src: 'hostapd/iiab-clone-wifi.service.j2', dest: '/etc/systemd/system/iiab-clone-wifi.service', mode : '0644' }
- { src: 'hostapd/iiab-wifi-test.service.j2', dest: '/etc/systemd/system/iiab-wifi-test.service', mode : '0644' }
- { src: 'hostapd/iiab-test-wifi.j2', dest: '/usr/sbin/iiab-test-wifi', mode : '0755' }
2021-12-17 10:10:31 +00:00
when : can_be_ap
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
2021-12-17 10:10:31 +00:00
when : not wifi_up_down and can_be_ap
2017-05-27 18:09:50 +00:00
2022-07-11 17:12:29 +00:00
# 2022-07-11: Install of iiab-hotspot-on|off moved to network/tasks/main.yml
# as required for Admin Console
2017-11-19 00:48:13 +00:00
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
2022-07-16 16:12:40 +00:00
daemon_reload : yes
2020-04-22 20:56:57 +00:00
with_items :
2021-07-28 02:36:07 +00:00
- iiab-clone-wifi.service
- iiab-wifi-test.service
2020-04-22 20:56:57 +00:00
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
2021-07-28 02:36:07 +00:00
- iiab-clone-wifi.service
- iiab-wifi-test.service
2020-04-22 17:38:49 +00:00
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
2023-04-23 21:11:03 +00:00
2023-04-27 15:40:04 +00:00
- name : Create /etc/hostapd/hostapd.conf and backup .iiab from template if needed
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 : can_be_ap
2023-04-23 21:11:03 +00:00
- name : Record host_country_code_applied and host_channel in network of {{ iiab_ini_file }}
ini_file :
dest : "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section : network
option : "{{ item.option }}"
value : "{{ item.value | string }}"
with_items :
- option : hostapd_enabled
value : "{{ hostapd_enabled }}"
- option : host_ssid
value : "{{ host_ssid }}"
- option : host_wifi_mode
value : "{{ host_wifi_mode }}"
2023-04-27 15:40:04 +00:00
- option : wifi_up_down
value : "{{ wifi_up_down }}"
2023-04-23 21:11:03 +00:00
- option : host_country_code_applied
value : "{{ host_country_code }}"
- option : host_channel
value : "{{ host_channel }}"
- name : Add 'network' variable 'current_client_channel' value if defined, to {{ iiab_ini_file }}
ini_file :
dest : "{{ iiab_ini_file }}"
section : network
option : "{{ item.option }}"
value : "{{ item.value | string }}"
with_items :
- option : client_wifi_channel
value : "{{ current_client_channel.stdout }}"
when : current_client_channel.stdout is defined