1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 19:52:06 +00:00
iiab/roles/captiveportal/tasks/main.yml
2020-01-22 12:26:55 -06:00

136 lines
4.7 KiB
YAML

# TO DO: move ~7 stanzas below into tasks/install.yml
- name: "Download & install packages: python3-dateutil, python3-jinja2"
package:
name: "{{ item }}"
state: present
with_items:
- python3-dateutil
- python3-jinja2
- name: Create directory /opt/iiab/captiveportal for scripts & templates; set owner to {{ apache_user }}
file:
path: /opt/iiab/captiveportal
state: directory
owner: "{{ apache_user }}"
- name: "Install 3 scripts from template: /opt/iiab/captiveportal/checkurls, /usr/sbin/iiab-make-cp-servers.py, /usr/sbin/iiab-divert-to-nginx"
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode }}"
with_items:
- { src: roles/captiveportal/templates/checkurls, dest: /opt/iiab/captiveportal/, mode: '0644' }
- { src: roles/captiveportal/templates/iiab-make-cp-servers.py, dest: /usr/sbin/, mode: '0755' }
- { src: roles/captiveportal/templates/iiab-divert-to-nginx, dest: /usr/sbin/, mode: '0755' }
- name: Install /opt/iiab/captiveportal/capture-wsgi.py from template (creates the server)
template:
src: capture-wsgi.py.j2
#src: roles/captiveportal/templates/capture-wsgi.py.j2
dest: /opt/iiab/captiveportal/capture-wsgi.py
mode: '0755'
- name: Copy files {simple.template, mac.template} into /opt/iiab/captiveportal/
copy:
src: "{{ item }}"
dest: /opt/iiab/captiveportal/
with_items:
- simple.template
#- roles/captiveportal/files/simple.template
- mac.template
#- roles/captiveportal/files/mac.template
#- name: Install /etc/systemd/system/uwsgi-captiveportal.service from template
# template:
# src: uwsgi-captiveportal.service
# #src: roles/captiveportal/templates/uwsgi-captiveportal.service
# dest: /etc/systemd/system/
- name: "Add 'captiveportal_installed: True' to {{ iiab_state_file }}"
lineinfile:
dest: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp: '^captiveportal_installed'
line: 'captiveportal_installed: True'
# TO DO: move most/all 7-10 stanzas below into enable-or-disable.yml
#- name: Restart & Enable 'uwsgi-captiveportal' systemd service (uWSGI server) that responds to browsers trying to detect a Captive Portal
# systemd:
# name: uwsgi-captiveportal
# daemon_reload: yes
# state: restarted
# enabled: True
# when: captiveportal_enabled | bool
#- name: Stop & Disable 'uwsgi-captiveportal' systemd service (uWSGI server) if Captive Portal has been disabled
# systemd:
# name: uwsgi-captiveportal
# state: stopped
# enabled: False
# when: not captiveportal_enabled
- name: Install uWSGI config file /etc/uwsgi/apps-enabled/captiveportal.ini from template
template:
src: captiveportal.ini.j2
#src: roles/captiveportal/templates/captiveportal.ini.j2
dest: /etc/uwsgi/apps-enabled/captiveportal.ini
when: captiveportal_enabled | bool
- name: Delete uWSGI config file /etc/uwsgi/apps-enabled/captiveportal.ini when disabled
file:
#src: /etc/nginx/sites-available/capture.conf
path: /etc/uwsgi/apps-enabled/captiveportal.ini
state: absent
when: not captiveportal_enabled
- name: Run iiab-divert-to-nginx to generate diversion lists for NGINX
shell: /usr/sbin/iiab-divert-to-nginx
- name: Run iiab-make-cp-servers.py to generate NGINX servers from checkurls input list (creates /etc/nginx/sites-available/capture.conf)
command: /usr/sbin/iiab-make-cp-servers.py
args:
creates: /etc/nginx/sites-available/capture.conf
- name: Symlink /etc/nginx/sites-enabled/capture.conf -> /etc/nginx/sites-available/capture.conf, to enable NGINX to service the sites in checkurls list
file:
src: /etc/nginx/sites-available/capture.conf
path: /etc/nginx/sites-enabled/capture.conf
state: link
when: captiveportal_enabled | bool
- name: Delete symlink /etc/nginx/sites-enabled/capture.conf, to disable NGINX to location definitions for checkurls
file:
#src: /etc/nginx/sites-available/capture.conf
path: /etc/nginx/sites-enabled/capture.conf
state: absent
when: not captiveportal_enabled
- name: Make sure dnsmasq is not diverting if not captiveportal_enabled
file:
path: /etc/dnsmasq.d/capture
state: absent
when: not captiveportal_enabled
# lets assume admin-console was/will be installed anyway
- name: Restart uwsgi
systemd:
name: uwsgi
daemon_reload: yes
state: restarted
enabled: true
- name: Stop 'dnsmasq' systemd service
systemd:
name: dnsmasq
state: stopped
when: dnsmasq_enabled | bool
- name: Start 'dnsmasq' systemd service
systemd:
name: dnsmasq
state: started
when: dnsmasq_enabled | bool
# TO DO: add important captiveportal_* variable values to {{ iiab_ini_file }} =
# /etc/iiab/iiab.ini at the end of main.yml here, for /usr/bin/iiab-diagnostics