1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 11:42:08 +00:00

Merge pull request #3272 from holta/0-init-faster

Speed up roles/0-init by almost 50% (by moving 2 things to detected_network.yml)
This commit is contained in:
A Holt 2022-06-29 20:20:58 -04:00 committed by GitHub
commit a225ad92a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 98 additions and 69 deletions

View file

@ -23,14 +23,6 @@
# ...after it is set in 0-init/tasks/main.yml # ...after it is set in 0-init/tasks/main.yml
first_run: False first_run: False
rpi_model: none # 2021-07-30: Broadly used! rpi_model: none # 2021-07-30: Broadly used!
#xo_model: none # 2021-07-30: No longer used
# 2021-07-30: Recorded to /etc/iiab/iiab.ini but not used programmatically:
gw_active: False
# 2021-07-30: Broadly used, but not in an organized way -- most all IIAB
# outfitting/provisioning happens online -- in situations where connectivity
# failures should be reported to the operator, rather than papered over:
internet_available: False
discovered_wan_iface: none # 2021-07-30: Very broadly used!
# 2021-07-30: Barely used -- for {named, dhcpd, squid} in # 2021-07-30: Barely used -- for {named, dhcpd, squid} in
# roles/network/tasks/main.yml -- after being set in 0-init/tasks/network.yml # roles/network/tasks/main.yml -- after being set in 0-init/tasks/network.yml

View file

@ -13,11 +13,6 @@
devicetree_model: "{{ ansible_local.local_facts.devicetree_model }}" devicetree_model: "{{ ansible_local.local_facts.devicetree_model }}"
iiab_stage: "{{ ansible_local.local_facts.stage }}" iiab_stage: "{{ ansible_local.local_facts.stage }}"
# 2020-10-29: Appears no longer nec (see 3 above ansible_local.local_facts.*)
#- name: Re-read local_facts.facts from /etc/ansible/facts.d
# setup:
# filter: ansible_local
# Initialize /etc/iiab/iiab.ini writing the 'location' and 'version' sections # Initialize /etc/iiab/iiab.ini writing the 'location' and 'version' sections
# once and only once, to preserve the install date and git hash. # once and only once, to preserve the install date and git hash.
- name: Create {{ iiab_ini_file }}, if it doesn't exist - name: Create {{ iiab_ini_file }}, if it doesn't exist
@ -26,9 +21,9 @@
# 2021-07-30: The 'first_run' flag isn't much used anymore. In theory it's # 2021-07-30: The 'first_run' flag isn't much used anymore. In theory it's
# still used in these 2 places: # still used in these 2 places:
# (1) roles/1-prep/tasks/main.yml for raspberry_pi.yml # (1) roles/1-prep/tasks/hardware.yml for raspberry_pi.yml
# (2) roles/network/tasks/named.yml for "Stop named before copying files" # (2) roles/network/tasks/named.yml for "Stop named before copying files"
# In practice however, it's no longer important, and might be reconsidered? # This needs to be reworked for 0-init speed, and overall understandability.
- name: Set first_run flag - name: Set first_run flag
set_fact: set_fact:
first_run: True first_run: True
@ -56,7 +51,7 @@
- name: "Time Zone / TZ: Set symlink /etc/localtime to UTC if it doesn't exist?" - name: "Time Zone / TZ: Set symlink /etc/localtime to UTC if it doesn't exist?"
include_tasks: tz.yml include_tasks: tz.yml
- name: Test Gateway + Test Internet + Set new hostname/domain (hostname.yml) if nec + Set 'gui_port' to 80 or 443 for Admin Console - name: Set new hostname/domain (hostname.yml) if nec
include_tasks: network.yml include_tasks: network.yml
@ -91,10 +86,6 @@
value: "{{ ansible_memtotal_mb }}" value: "{{ ansible_memtotal_mb }}"
- option: swap_mb - option: swap_mb
value: "{{ ansible_swaptotal_mb }}" value: "{{ ansible_swaptotal_mb }}"
- option: gw_active
value: "{{ gw_active }}"
- option: internet_available
value: "{{ internet_available }}"
- option: rpi_model - option: rpi_model
value: "{{ rpi_model }}" value: "{{ rpi_model }}"
- option: devicetree_model - option: devicetree_model

View file

@ -1,46 +1,3 @@
- name: Do we have a gateway? If 'ip route' specifies a default route, Ansible parses details here...
debug:
var: ansible_default_ipv4
- name: "If above ansible_default_ipv4.gateway is defined, set WAN candidate 'discovered_wan_iface: {{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias"
set_fact:
discovered_wan_iface: "{{ ansible_default_ipv4.alias }}"
when: ansible_default_ipv4.gateway is defined
- name: "Verify gateway active: ping -c4 {{ ansible_default_ipv4.gateway }} -- using ansible_default_ipv4.gateway"
shell: ping -c4 "{{ ansible_default_ipv4.gateway }}" | grep icmp_seq=4 | wc -l
register: gw_active_test
when: discovered_wan_iface != "none"
- name: "If gateway responded, set 'gw_active: True' and 'iiab_wan_iface: {{ discovered_wan_iface }}' -- using discovered_wan_iface"
set_fact:
iiab_wan_iface: "{{ discovered_wan_iface }}"
gw_active: True
when: discovered_wan_iface != "none" and gw_active_test.stdout == "1"
- name: 'Test for Internet access, using: {{ iiab_download_url }}/heart-beat.txt'
get_url:
url: "{{ iiab_download_url }}/heart-beat.txt"
dest: /tmp/heart-beat.txt
#timeout: "{{ download_timeout }}"
# @jvonau recommends: 100sec is too much (keep 10sec default)
ignore_errors: True
#async: 10
#poll: 2
register: internet_access_test
- name: "Set 'internet_available: True' if above download succeeded AND not disregard_network"
set_fact:
internet_available: True # Initialized to 'False' in 0-init/defaults/main.yml
when: not internet_access_test.failed and not disregard_network
- name: Remove downloaded Internet test file /tmp/heart-beat.txt
file:
path: /tmp/heart-beat.txt
state: absent
- name: "Set 'iiab_fqdn: {{ iiab_hostname }}.{{ iiab_domain }}'" - name: "Set 'iiab_fqdn: {{ iiab_hostname }}.{{ iiab_domain }}'"
set_fact: set_fact:
iiab_fqdn: "{{ iiab_hostname }}.{{ iiab_domain }}" iiab_fqdn: "{{ iiab_hostname }}.{{ iiab_domain }}"

View file

@ -71,7 +71,10 @@
# when: not is_debuntu and selinux_disabled is defined and selinux_disabled.changed # when: not is_debuntu and selinux_disabled is defined and selinux_disabled.changed
- name: Recording STAGE 1 HAS COMPLETED ============================ - name: Install {{ iiab_env_file }} from template -- FYI this file can be run as a script if absolutely nec -- e.g. 'source /etc/iiab/iiab.env && echo $WWWROOT'
template: template:
src: roles/1-prep/templates/iiab.env.j2 src: roles/1-prep/templates/iiab.env.j2
dest: "{{ iiab_env_file }}" # Can also be run as a script if absolutely nec, e.g. 'source /etc/iiab/iiab.env && echo $WWWROOT' dest: "{{ iiab_env_file }}"
- name: Recording STAGE 1 HAS COMPLETED ============================
meta: noop

View file

@ -27,6 +27,10 @@
# hostapd_enabled: True # hostapd_enabled: True
# Above set in /opt/iiab/iiab/vars/default_vars.yml # Above set in /opt/iiab/iiab/vars/default_vars.yml
# 2022-06-29: Legacy vars no longer used by roles/0-init
gw_active: False # 2021-07-30: Not used propgrammatically
discovered_wan_iface: none # 2021-07-30: Very broadly used!
hostapd_wait: 10 hostapd_wait: 10
host_wireless_n: False host_wireless_n: False
driver_name: nl80211 driver_name: nl80211

View file

@ -1,3 +1,48 @@
# Similar code block in roles/vnstat/tasks/install.yml
- name: Do we have a gateway? If 'ip route' specifies a default route, Ansible parses details here...
debug:
var: ansible_default_ipv4
- name: "If above ansible_default_ipv4.gateway is defined, set WAN candidate 'discovered_wan_iface: {{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias"
set_fact:
discovered_wan_iface: "{{ ansible_default_ipv4.alias }}"
when: ansible_default_ipv4.gateway is defined
- name: "Verify gateway active: ping -c4 {{ ansible_default_ipv4.gateway }} -- using ansible_default_ipv4.gateway"
shell: ping -c4 "{{ ansible_default_ipv4.gateway }}" | grep icmp_seq=4 | wc -l
register: gw_active_test
when: discovered_wan_iface != "none"
- name: "If gateway responded, set 'gw_active: True' and 'iiab_wan_iface: {{ discovered_wan_iface }}' -- using discovered_wan_iface"
set_fact:
iiab_wan_iface: "{{ discovered_wan_iface }}" # Same as code on Line 70 !
gw_active: True
when: discovered_wan_iface != "none" and gw_active_test.stdout == "1"
# Similar to roles/www_options/tasks/main.yml prereq for iiab-refresh-wiki-docs
- name: 'Test for Internet access, using: {{ iiab_download_url }}/heart-beat.txt'
get_url:
url: "{{ iiab_download_url }}/heart-beat.txt"
dest: /tmp/heart-beat.txt
#timeout: "{{ download_timeout }}"
# @jvonau recommends: 100sec is too much (keep 10sec default)
ignore_errors: True
#async: 10
#poll: 2
register: internet_access_test
- name: "Set 'internet_available: True' if above download succeeded AND not disregard_network"
set_fact:
internet_available: True # Initialized to 'False' in 0-init/defaults/main.yml
when: not internet_access_test.failed and not disregard_network
- name: Remove downloaded Internet test file /tmp/heart-beat.txt
file:
path: /tmp/heart-beat.txt
state: absent
# so this works # so this works
- name: Interface count - name: Interface count
shell: ls /sys/class/net | grep -v {{ virtual_network_devices }} | wc | awk '{print $1}' shell: ls /sys/class/net | grep -v {{ virtual_network_devices }} | wc | awk '{print $1}'
@ -239,6 +284,10 @@
option: "{{ item.option }}" option: "{{ item.option }}"
value: "{{ item.value | string }}" value: "{{ item.value | string }}"
with_items: with_items:
- option: gw_active
value: "{{ gw_active }}"
- option: internet_available
value: "{{ internet_available }}"
- option: has_ifcfg_gw - option: has_ifcfg_gw
value: "{{ has_ifcfg_gw }}" value: "{{ has_ifcfg_gw }}"
- option: prior_gateway_device - option: prior_gateway_device

View file

@ -3,7 +3,7 @@
url: "{{ phpmyadmin_dl_url }}" # e.g. https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.zip url: "{{ phpmyadmin_dl_url }}" # e.g. https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.zip
dest: "{{ downloads_dir }}" # /opt/iiab/downloads dest: "{{ downloads_dir }}" # /opt/iiab/downloads
timeout: "{{ download_timeout }}" timeout: "{{ download_timeout }}"
when: internet_available #when: internet_available
- name: Does {{ downloads_dir }}/{{ phpmyadmin_name_zip }} exist? - name: Does {{ downloads_dir }}/{{ phpmyadmin_name_zip }} exist?
stat: stat:

View file

@ -1,3 +1,20 @@
# Similar code block in roles/network/tasks/detected_network.yml
- name: "If above ansible_default_ipv4.gateway is defined, set WAN candidate 'discovered_wan_iface: {{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias"
set_fact:
discovered_wan_iface: "{{ ansible_default_ipv4.alias }}"
when: ansible_default_ipv4.gateway is defined
- name: "Verify gateway active: ping -c4 {{ ansible_default_ipv4.gateway }} -- using ansible_default_ipv4.gateway"
shell: ping -c4 "{{ ansible_default_ipv4.gateway }}" | grep icmp_seq=4 | wc -l
register: gw_active_test
when: discovered_wan_iface != "none"
- name: "If gateway responded, set 'gw_active: True' and 'iiab_wan_iface: {{ discovered_wan_iface }}' -- using discovered_wan_iface"
set_fact:
iiab_wan_iface: "{{ discovered_wan_iface }}"
when: discovered_wan_iface != "none" and gw_active_test.stdout == "1"
- name: Install 'vnstat' package - name: Install 'vnstat' package
package: package:
name: vnstat name: vnstat
@ -7,10 +24,9 @@
template: template:
src: vnstat.conf.j2 src: vnstat.conf.j2
dest: /etc/vnstat.conf dest: /etc/vnstat.conf
# owner: root
# group: root
mode: '0744' mode: '0744'
- name: Create database for WAN to collect vnStat data - name: Create database for WAN to collect vnStat data
shell: /usr/bin/vnstat -i {{ iiab_wan_iface }} shell: /usr/bin/vnstat -i {{ iiab_wan_iface }}

View file

@ -154,9 +154,26 @@
when: not apache_allow_sudo when: not apache_allow_sudo
# internet_available var moved to roles/network/tasks/detected_network.yml
- name: 'Test for Internet access, using: {{ iiab_download_url }}/heart-beat.txt'
get_url:
url: "{{ iiab_download_url }}/heart-beat.txt"
dest: /tmp/heart-beat.txt
#timeout: "{{ download_timeout }}"
# @jvonau recommends: 100sec is too much (keep 10sec default)
ignore_errors: True
#async: 10
#poll: 2
register: internet_access_test
- name: Remove downloaded Internet test file /tmp/heart-beat.txt
file:
path: /tmp/heart-beat.txt
state: absent
- name: Run /usr/bin/iiab-refresh-wiki-docs (scraper script) to create http://box/info offline documentation. (This script was installed in Stage 3 = roles/3-base-server/tasks/main.yml, which ran roles/www_base/tasks/main.yml) - name: Run /usr/bin/iiab-refresh-wiki-docs (scraper script) to create http://box/info offline documentation. (This script was installed in Stage 3 = roles/3-base-server/tasks/main.yml, which ran roles/www_base/tasks/main.yml)
command: /usr/bin/iiab-refresh-wiki-docs command: /usr/bin/iiab-refresh-wiki-docs
when: internet_available and not nodocs when: not internet_access_test.failed and not nodocs
- name: (Re)Start '{{ apache_service }}' systemd service, if installed & enabled - name: (Re)Start '{{ apache_service }}' systemd service, if installed & enabled