Configure wpa_cli by config_light
To configure the image, we’ll use Ansible role vbotka.config_light, instead of the Customization tasks. This example,
using config_light, configures exactly the same parameters of the wireless network as the role
vbotka.freebsd_wpa_cli. Review the goal of
Ansible role FreeBSD wpa_cli and read at least the
Introduction. The purpose of
using the role config_light, instead of freebsd_wpa_cli, is building single source of the
configuration in the directory cl_dird
.
The playbook pb-wifi-basic.yml
created in the Quick start guide will be used to attach a memory disk and
mount the partition.
Current directory reuses the data from the previous example
shell> ls -1 conf-light files hosts pb-wpacli-cl.yml pb-wifi-basic.yml
Install the role
vbotka.config_light
shell> ansible-galaxy install vbotka.freebsd_config_light
Create the playbook
pb-wpacli-cl.yml
for single host images.example.com (1). Configure connection (3-4) and privilege escalation (5-7). Configure the directory (12) with the configuration files and reuse the configuration (14-17) already prepared in Quick start guide (28-55). Configure only wlan0 (18) in wpa_supplicant. The configuration of wpa_cli (58-78) is described in Ansible role vbotka.freebsd_wpa_cli. The configuration of ntp (81-94) is described in Ansible role vbotka.freebsd_postinstall.
1- name: Configure wireless network and wpa_cli in the mounted system image
2 hosts: images.example.com
3
4 connection: ssh
5 remote_user: admin
6 become: true
7 become_user: root
8 become_method: ansible.builtin.sudo
9
10 vars:
11
12 # config_light - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13 cl_dird: "{{ playbook_dir }}/conf-light"
14 cl_assemble_validate: ansible-lint -x 205 %s
15 cl_loaderconf_modules: "{{ bsd_cimage_loaderconf_modules }}"
16 cl_loaderconf_data: "{{ bsd_cimage_loaderconf_data }}"
17 cl_loaderconf_sysctl: "{{ bsd_cimage_loaderconf_sysctl }}"
18 cl_wpasupconf_global: "{{ bsd_cimage_wpasupconf_global }}"
19 cl_wpasupconf_wlan0: "{{ bsd_cimage_wpasupconf_data|selectattr('dev', 'eq', 'wlan0')|first }}"
20
21 # freebsd_custom_image - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 bsd_cimage_sanity: false
23 bsd_cimage_install: false
24 bsd_cimage_debug: true
25 bsd_cimage_debug_classified: true
26
27 bsd_cimage_mount_path: /mnt3
28
29 bsd_cimage_loaderconf_modules: [wlan, wlan_wep, wlan_ccmp, wlan_tkip, wlan_amrr, rtwn, if_rtwn_usb]
30 bsd_cimage_loaderconf_data:
31 - hw.usb.template=3
32 - umodem_load="YES"
33 - boot_multicons="YES"
34 - boot_serial="YES"
35 - beastie_disable="YES"
36 - loader_color="NO"
37 - legal.realtek.license_ack=1
38 bsd_cimage_loaderconf_sysctl: []
39 bsd_cimage_rcconf_data: "{{ wpacli_rcconf }}"
40 # - {key: wlans_rtwn0, value: '"wlan0"'}
41 # - {key: ifconfig_wlan0, value: '"WPA SYNCDHCP"'}
42
43 bsd_cimage_wpasupconf_global:
44 - { key: ctrl_interface, value: /var/run/wpa_supplicant }
45 - { key: ctrl_interface_group, value: wheel }
46 - { key: fast_reauth, value: "1" }
47 bsd_cimage_wpasupconf_data:
48 - dev: wlan0
49 network:
50 - conf:
51 - { key: ssid, value: '"my_access_point"' }
52 - { key: psk, value: '"my_password"' }
53 - { key: disabled, value: "0" }
54 bsd_cimage_wpasupconf_link: true
55 bsd_cimage_wpasupconf_link_dev: wlan0
56
57 # freebsd_wpa_cli - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 wpacli_enable: "YES"
59 wpacli_program: /usr/sbin/wpa_cli
60 wpacli_action_script_dir: /root/bin
61 wpacli_action_script_file: wpa_action.sh
62 wpacli_action_script_log_to_file: true
63 wpacli_action_script_logfile: /tmp/wpa_action.$ifname
64 wpacli_action_script_ntp_set: true
65 wpacli_action_script_ntp_server: "0.pool.ntp.org"
66 wpacli_action_script_ntpdate_flags: -b
67 wpacli_rcconf:
68 - { key: wlans_rtwn0, value: '"wlan0"' }
69 - { key: ifconfig_wlan0, value: '"WPA"' }
70 - { key: defaultrouter, value: '"10.1.0.10"' }
71 - { key: wpa_cli_enable, value: '"{{ wpacli_enable }}"' }
72 - { key: wpa_cli_program, value: '"{{ wpacli_program }}"' }
73 - { key: wpa_cli_ctrl_interface, value: '"/var/run/wpa_supplicant"' }
74 - { key: wpa_cli_action_file, value: '"{{ wpacli_action_script_dir }}/{{ wpacli_action_script_file }}"' }
75 - { key: ntpd_enable, value: '"YES"' }
76 - { key: ntpd_sync_on_start, value: '"NO"' }
77 - { key: ntpdate_enable, value: '"NO"' }
78 - { key: ntpdate_flags, value: '"-b"' }
79
80 # freebsd_postinstall - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 fp_ntp_config_options:
82 - tos minclock 3 maxclock 6
83 fp_ntp_config_pool:
84 - "0.pool.ntp.org iburst"
85 - 1.pool.ntp.org iburst
86 - 2.pool.ntp.org iburst
87 - 3.pool.ntp.org iburst
88 fp_ntp_config_restrict:
89 - default limited kod nomodify notrap nopeer noquery
90 - -6 default limited kod nomodify notrap nopeer noquery
91 - 127.0.0.1
92 - -6 ::1
93 - 127.127.1.0
94 fp_ntp_config_leapfile: /var/db/ntpd.leap-seconds.list
95
96 roles:
97 - vbotka.config_light
98
99# EOF
Create the configuration files in the directory
cl_dird
shell> tree conf-light/ conf-light/ ├── files.d │ ├── defaults-rc-conf.yml │ ├── loader-conf.yml │ ├── network_subr.yml │ ├── ntp-conf.yml │ ├── rc-conf.yml │ ├── wpa-action-sh.yml │ ├── wpa-cli.yml │ └── wpasup-conf-wlan0.yml ├── handlers.d ├── packages.d ├── services.d └── states.d ├── root-bin.yml └── wpasup-conf.yml
Create the directory wiht the patches
shell> tree files/ files/ ├── network.subr.patch └── rc.conf.patch
<TODO: Details in contrib/example-wpacli-cl
>
See also
How to configure Files in vbotka.config_light
Create the inventory. Change the IP adress (2) and fit the paths to Python (8) and Perl (9) if necessary
1 shell> cat hosts
2 images.example.com ansible_host=<ip-address>
3
4 [images]
5 images.example.com
6
7 [images:vars]
8 ansible_python_interpreter=/usr/local/bin/python3.7
9 ansible_perl_interpreter=/usr/local/bin/perl
Mount the image using the playbook prepared in Quick start guide
shell> ansible-playbook pb-wifi-basic.yml -t bsd_cimage_mount
Test syntax
shell> ansible-playbook pb-wpacli-cl.yml --syntax-check
See what variables will be included
shell> ansible-playbook pb-wpacli-cl.yml -t cl_debug -e cl_debug=true
Run the playbook
shell> ansible-playbook pb-wpacli-cl.yml
Umount the partition and detach the memory disk
shell> ansible-playbook pb-wifi-basic.yml -t bsd_cimage_umount
Write the customized image to a disk and boot the system. Connect to the system and review the log. For example
shell> cat /tmp/wpa_action.wlan0 Jan 21 06:29:49 wlan0: CONNECTED Jan 21 06:29:50 wlan0: SSID: my-access-point Jan 21 06:29:57 wlan0: /etc/rc.d/dhclient forcestart wlan0: Starting dhclient. DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPACK from 10.1.0.1 bound to 10.1.0.16 -- renewal in 21600 seconds. Jan 21 06:30:03 wlan0: /etc/rc.d/routing restart: delete host 127.0.0.1: gateway lo0 route: route has not been found delete net default: gateway 10.1.0.10 fib 0: not in table default 10.1.0.1 -fib 0 done route: route has not been found delete host ::1: gateway lo0 fib 0: not in table delete net fe80::: gateway ::1 delete net ff02::: gateway ::1 delete net ::ffff:0.0.0.0: gateway ::1 delete net ::0.0.0.0: gateway ::1 add host 127.0.0.1: gateway lo0 add net default: gateway 10.1.0.10 add host ::1: gateway lo0 fib 0: route already in table add net fe80::: gateway ::1 add net ff02::: gateway ::1 add net ::ffff:0.0.0.0: gateway ::1 add net ::0.0.0.0: gateway ::1 Jan 21 06:30:04 wlan0: /etc/rc.d/ntpd stop: ntpd not running? (check /var/db/ntp/ntpd.pid). Jan 21 06:31:05 wlan0: /usr/sbin/ntpdate -b 0.pool.ntp.org: 21 Jan 06:31:05 ntpdate[999]: step time server 62.168.94.161 offset +54.261588 sec Jan 21 06:31:08 wlan0: /etc/rc.d/ntpd start: Starting ntpd.