From e7872a2a9da875e47e29c4bb21771c12104cd68e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 7 Apr 2018 11:50:13 -0500 Subject: [PATCH 1/5] fix enabling hostapd --- roles/network/tasks/hostapd.yml | 7 ++----- roles/network/tasks/rpi_debian.yml | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index f0c8e9fbe..dc4cee801 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -46,9 +46,6 @@ group: root mode: 0755 -- name: Enable/Restart the Access Point 'hostapd' service - service: - # enabled: yes - state: restarted - name: hostapd.service +- name: Ansible is having a problem enabling hostapd service + shell: systemctl enable hostapd when: hostapd_enabled and iiab_wireless_lan_iface is defined and iiab_network_mode != "Appliance" diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index be4ea571a..ec9b59143 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -67,10 +67,6 @@ state: restarted when: hostapd_enabled and iiab_wan_iface != discovered_wireless_iface and iiab_network_mode != "Appliance" -- name: Ansible is having a problem enabling services - shell: systemctl enable hostapd - when: hostapd_enabled and iiab_wan_iface != discovered_wireless_iface and iiab_network_mode != "Appliance" - #- name: dhcp_server may be affected - starting - user choice # service: name={{ dhcp_service2 }} state=started # when: iiab_network_mode != "Appliance" From 367164029ca42fe873d3dfac1174fe9c365bac95 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 7 Apr 2018 16:45:04 -0500 Subject: [PATCH 2/5] replace shell use of daemon_reload with systemd module, use systemd module in place of service for hostapd --- roles/network/tasks/NM-debian.yml | 17 +++-------------- roles/network/tasks/debian.yml | 11 ++--------- roles/network/tasks/hostapd.yml | 18 ++++++++++-------- roles/network/tasks/ifcfg_mods.yml | 8 +++++--- roles/network/tasks/restart.yml | 12 +++++++----- roles/network/tasks/rpi_debian.yml | 13 ++----------- roles/network/tasks/sysd-netd-debian.yml | 16 +++------------- 7 files changed, 32 insertions(+), 63 deletions(-) diff --git a/roles/network/tasks/NM-debian.yml b/roles/network/tasks/NM-debian.yml index a7ece265e..23ecc9dd2 100644 --- a/roles/network/tasks/NM-debian.yml +++ b/roles/network/tasks/NM-debian.yml @@ -29,22 +29,11 @@ when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance" - name: Reload systemd - shell: systemctl daemon-reload + systemd: + daemon_reload: yes - name: Restart the NetworkManager service - service: + systemd: name: network-manager state: restarted when: not nobridge is defined and not no_net_restart - -- name: Restart hostapd when WiFi is present - service: - name: hostapd - state: restarted - when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance" - -- name: dhcp_server may be affected - starting - user choice - service: - name: "{{ dhcp_service2 }}" - state: started - when: iiab_network_mode != "Appliance" diff --git a/roles/network/tasks/debian.yml b/roles/network/tasks/debian.yml index 69ae60cbd..e2103047d 100644 --- a/roles/network/tasks/debian.yml +++ b/roles/network/tasks/debian.yml @@ -58,7 +58,8 @@ when: dnsmasq_install - name: Reload systemd - shell: systemctl daemon-reload + systemd: + daemon_reload: yes # now pick up denyinterfaces - name: Restart dhcpcd @@ -68,11 +69,3 @@ - name: Restart the networking service service: name=networking state=restarted when: not nobridge is defined and not no_net_restart - -- name: Restart hostapd when WiFi is present - service: name=hostapd state=restarted - when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance" - -#- name: dhcp_server may be affected - starting - user choice -# service: name={{ dhcp_service2 }} state=started -# when: iiab_network_mode != "Appliance" diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index dc4cee801..2f9f71e5c 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -16,12 +16,6 @@ mode: 0644 when: discovered_wireless_iface is defined -- name: Disable the Access Point 'hostapd' service - service: - enabled: no - name: hostapd.service - when: not hostapd_enabled - - name: Use custom systemd unit file to start 'hostapd' service template: src: hostapd/hostapd.service.j2 @@ -46,6 +40,14 @@ group: root mode: 0755 -- name: Ansible is having a problem enabling hostapd service - shell: systemctl enable hostapd +- name: Disable the Access Point 'hostapd' service + systemd: + name: hostapd + enabled: no + when: not hostapd_enabled + +- name: Enable the Access Point 'hostapd' service + systemd: + name: hostapd + enabled: yes when: hostapd_enabled and iiab_wireless_lan_iface is defined and iiab_network_mode != "Appliance" diff --git a/roles/network/tasks/ifcfg_mods.yml b/roles/network/tasks/ifcfg_mods.yml index 2d8a4769f..b5a3f5f9c 100644 --- a/roles/network/tasks/ifcfg_mods.yml +++ b/roles/network/tasks/ifcfg_mods.yml @@ -1,6 +1,7 @@ - name: Stop the Access Point hostapd program - service: name=hostapd.service - state=stopped + systemd: + name: hostapd + state: stopped when: iiab_wireless_lan_iface != "none" # might need an exclude for F18 here @@ -81,7 +82,8 @@ when: not installing and not iiab_demo_mode - name: ask systemd to reread the unit files, picks up changes done - shell: systemctl daemon-reload + systemd: + daemon_reload: yes when: not installing # monitor-connection-files defaults to no with F21, F18-F20 defaults to yes diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 98fc09114..30aa4b307 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -1,6 +1,8 @@ -#- name: restart hostapd when wifi is present -# service: name=hostapd state=started -# when: iiab_wireless_lan_iface is defined and hostapd_enabled +- name: restart hostapd when wifi is present + systemd: + name: hostapd + state: restarted + when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance" - name: Start named service service: @@ -63,8 +65,8 @@ register: wifi_slave - name: Restart hostapd if WiFi slave is inactive - service: - name: hostapd.service + systemd: + name: hostapd state: restarted when: hostapd_enabled and wifi_slave.stdout is defined and wifi_slave.stdout == 0 diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index ec9b59143..406c70e07 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -46,7 +46,8 @@ include_tasks: down-debian.yml - name: Reload systemd - shell: systemctl daemon-reload + systemd: + daemon_reload: yes # now pick up denyinterfaces - name: Restart dhcpcd @@ -60,13 +61,3 @@ enabled: yes state: restarted when: not nobridge is defined and not no_net_restart - -- name: Restart hostapd if appropriate - service: - name: hostapd - state: restarted - when: hostapd_enabled and iiab_wan_iface != discovered_wireless_iface and iiab_network_mode != "Appliance" - -#- name: dhcp_server may be affected - starting - user choice -# service: name={{ dhcp_service2 }} state=started -# when: iiab_network_mode != "Appliance" diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 6e94c9c1f..08e09f1bc 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -19,22 +19,12 @@ include_tasks: down-debian.yml - name: Reload systemd - shell: systemctl daemon-reload + systemd: + daemon_reload: yes - name: Restart the systemd-networkd service - service: + systemd: name: systemd-networkd enabled: yes state: restarted when: not nobridge is defined and not no_net_restart - -- name: Restart hostapd when WiFi is present - service: - name: hostapd - enabled: yes - state: restarted - when: iiab_wireless_lan_iface is defined and hostapd_enabled and iiab_network_mode != "Appliance" - -#- name: dhcp_server may be affected - starting - user choice -# service: name={{ dhcp_service2 }} state=started -# when: iiab_network_mode != "Appliance" From ceb4d7d901afaf57e706914ef903124b05130278 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 8 Apr 2018 19:22:57 -0500 Subject: [PATCH 3/5] hostapd - disable before enable Similar workarounds exist in named.yml and dhcpd.yml, just go with the flow --- roles/network/tasks/enable_services.yml | 6 ------ roles/network/tasks/hostapd.yml | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/roles/network/tasks/enable_services.yml b/roles/network/tasks/enable_services.yml index 243342c15..ee7b395d0 100644 --- a/roles/network/tasks/enable_services.yml +++ b/roles/network/tasks/enable_services.yml @@ -1,9 +1,3 @@ -- name: Disable the Access Point 'hostapd' service - service: enabled=no - name=hostapd.service - when: not iiab_wireless_lan_iface is defined or iiab_network_mode == "Appliance" -#or not hostapd_enabled - - name: Disable dhcpd service service: name=dhcpd enabled=no diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 2f9f71e5c..1b165f4ff 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -44,7 +44,8 @@ systemd: name: hostapd enabled: no - when: not hostapd_enabled +# cheap workaround for when /etc/init.d is populated +# when: not hostapd_enabled - name: Enable the Access Point 'hostapd' service systemd: From 5a0a37d064eb0e2cf76e788d5919d1f833e235be Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 8 Apr 2018 19:46:31 -0500 Subject: [PATCH 4/5] scripts only apply to the RPi --- roles/network/tasks/hostapd.yml | 9 +++++++++ roles/network/tasks/main.yml | 10 ---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 1b165f4ff..f27e60470 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -31,6 +31,7 @@ owner: root group: root mode: 0755 + when: is_rpi - name: Create /usr/bin/iiab-hotspot-off from template template: @@ -39,6 +40,7 @@ owner: root group: root mode: 0755 + when: is_rpi - name: Disable the Access Point 'hostapd' service systemd: @@ -52,3 +54,10 @@ name: hostapd enabled: yes when: hostapd_enabled and iiab_wireless_lan_iface is defined and iiab_network_mode != "Appliance" + +- name: Record HOSTAPD_ENABLED to /etc/iiab/iiab.env + lineinfile: + dest: /etc/iiab/iiab.env + regexp: '^HOSTAPD_ENABLED=*' + line: 'HOSTAPD_ENABLED={{ hostapd_enabled }}' + state: present diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index cc595770b..2c36298a3 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -19,16 +19,6 @@ # be encapsulated into roles/network/tasks/hostapd.yml in future? Whereas # today "./runtags hostapd" doesn't exist & "./runtags AP" is UNSUPPORTED! -- name: Record HOSTAPD_ENABLED to /etc/iiab/iiab.env - lineinfile: - dest: /etc/iiab/iiab.env - regexp: '^HOSTAPD_ENABLED=*' - line: 'HOSTAPD_ENABLED={{ hostapd_enabled }}' - state: present - #when: not installing #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml - tags: - - network - #- name: RPi - reboot to AP post install - installed via wifi so the services are ready # set_fact: # iiab_lan_iface: br0 From 50ad0de6be9ae68aedc260c0c47a75218cfaa297 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 8 Apr 2018 19:57:49 -0500 Subject: [PATCH 5/5] revise feedback --- iiab-network | 4 ++-- roles/network/tasks/main.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iiab-network b/iiab-network index 65c77b55a..563ecace6 100755 --- a/iiab-network +++ b/iiab-network @@ -19,11 +19,11 @@ fi OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit if [ -f /etc/iiab/iiab.env ]; then - echo "Running /etc/iiab/iiab.env" + echo "Reading /etc/iiab/iiab.env" source /etc/iiab/iiab.env fi -echo "Ansible will now run iiab-network.yml -- monitor log file iiab-network.log" +echo "Ansible will now run iiab-network.yml -- log file is iiab-network.log" Start=`date` ansible-playbook -i ansible_hosts iiab-network.yml --connection=local End=`date` diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 2c36298a3..f1adc8d92 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -12,7 +12,7 @@ # (2) debian.yml, (3) rpi_debian.yml when: discovered_wireless_iface == iiab_wan_iface and not reboot_to_AP # EITHER WAY: hostapd_enabled's state is RECORDED into /etc/iiab/iiab.env -# (happens just below) for later use by... +# in hostapd.yml for later use by... # /usr/libexec/iiab-startup.sh, iiab-hotspot-off & iiab-hotspot-on # # Separate Idea, Not Without Risks: should WiFi-as-gateway detection logic