Files
dsfin-ansible/roles/ap/tasks/main.yaml

105 lines
2.4 KiB
YAML

---
- name: Remove wpasupplicant package
become: yes
apt:
name: ['wpasupplicant']
state: absent
purge: true
tags: wireless_ap
- name: configure wlan0
become: true
blockinfile:
path: /etc/dhcpcd.conf
block: |
interface wlan0
static ip_address=10.250.250.1/29
nohook wpa_supplicant
tags: wireless_ap
- name: install hostapd
become: true
apt:
name: ['hostapd']
state: present
tags: wireless_ap
- name: configure hostapd
become: true
template:
src: "{{ role_path }}/templates/hostapd.conf.j2"
dest: "/etc/hostapd/hostapd.conf"
owner: root
group: root
backup: yes
tags: wireless_ap
- name: configure hostapd startup
become: true
tags: wireless_ap
lineinfile:
state: present
path: "{{ item.path }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { path: "/etc/init.d/hostapd", regexp: "^DAEMON_CONF=", line: "DAEMON_CONF=/etc/hostapd/hostapd.conf" }
- { path: "/etc/default/hostapd", regexp: "^#DAEMON_CONF=", line: "DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"" }
- name: enable hostapd
become: true
systemd:
name: hostapd
enabled: yes
masked: no
state: restarted
tags: wireless_ap
- name: install dnsmasq
become: true
apt:
name: ['dnsmasq']
state: present
tags: wireless_ap
- name: configure dnsmasq
become: true
copy:
src: "{{ role_path }}/files/dnsmasq.conf"
dest: "/etc/dnsmasq.conf"
backup: yes
owner: root
group: root
tags: wireless_ap
- name: enable dnsmasq
become: true
systemd:
name: dnsmasq
enabled: yes
masked: no
state: restarted
tags: wireless_ap
- name: lan to wlan
iptables:
chain: FORWARD
ctstate: ESTABLISHED,RELATED
jump: ACCEPT
in_interface: eth0
out_interface: wlan0
become: yes
- name: wlan to lan
iptables:
chain: FORWARD
jump: ACCEPT
in_interface: wlan0
out_interface: eth0
become: yes
- name: forwarding
iptables:
chain: POSTROUTING
out_interface: eth0
table: nat
jump: MASQUERADE
become: yes
- name: restart dhcpcd
become: true
systemd:
name: dhcpcd
enabled: yes
masked: no
state: restarted
tags: wireless_ap