From eec9500192ec689daf7e283a558a4f3fcad610da Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 18 Jan 2020 22:58:22 -0600 Subject: [PATCH 01/16] don't override --- roles/nginx/tasks/install.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/nginx/tasks/install.yml b/roles/nginx/tasks/install.yml index 301120a65..cf7b1f896 100644 --- a/roles/nginx/tasks/install.yml +++ b/roles/nginx/tasks/install.yml @@ -27,7 +27,6 @@ - { src: 'roles/nginx/templates/server.conf.j2', dest: '/etc/nginx/server.conf' } - { src: 'roles/nginx/templates/nginx.conf.j2', dest: '/etc/nginx/nginx.conf' } - { src: 'roles/nginx/templates/ports.conf.j2', dest: '/etc/{{ apache_service }}/ports.conf' } - - { src: 'roles/nginx/templates/uwsgi.service', dest: '/etc/systemd/system/' } - name: Let uwsgi (running as {{ apache_user }}) write log files file: From 9c19f9112f2a1c1aecb8d1c5adec2832c076d8f1 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 18 Jan 2020 22:59:55 -0600 Subject: [PATCH 02/16] use apps-enabled in place of service file --- roles/captiveportal/tasks/main.yml | 60 +++++++++++++++++------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/roles/captiveportal/tasks/main.yml b/roles/captiveportal/tasks/main.yml index 27c0a1760..082de91b1 100644 --- a/roles/captiveportal/tasks/main.yml +++ b/roles/captiveportal/tasks/main.yml @@ -41,11 +41,11 @@ - mac.template #- roles/captiveportal/files/mac.template -- name: Install uWSGI config file /opt/iiab/captiveportal/captiveportal.ini from template - template: - src: captiveportal.ini.j2 - #src: roles/captiveportal/templates/captiveportal.ini.j2 - dest: /opt/iiab/captiveportal/captiveportal.ini +#- 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: @@ -55,25 +55,33 @@ # TO DO: move most/all 7-10 stanzas below into enable-or-disable.yml -- 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: 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: 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 +#- 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: Stop & Disable 'uwsgi-captiveportal' systemd service (uWSGI server) if Captive Portal has been disabled - systemd: - name: uwsgi-captiveportal - state: stopped - enabled: False +- 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 @@ -104,11 +112,11 @@ state: absent when: not captiveportal_enabled -#- name: Restart dnsmasq -# systemd: -# name: dnsmasq -# state: restarted -# when: dnsmasq_enabled | bool +- name: Restart uwsgi + systemd: + name: uwsgi + state: restarted + daemon_reload: yes # ABOVE DOES NOT WORK ON UBUNTU 16.04 -- what follows is a crude hack (seems to work!) From cad855ec2583c4a123d1ff9b6c9fc87480ef868c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 18 Jan 2020 23:00:23 -0600 Subject: [PATCH 03/16] adjust logging --- roles/captiveportal/templates/capture-wsgi.py.j2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/captiveportal/templates/capture-wsgi.py.j2 b/roles/captiveportal/templates/capture-wsgi.py.j2 index 944ee556e..805e79213 100755 --- a/roles/captiveportal/templates/capture-wsgi.py.j2 +++ b/roles/captiveportal/templates/capture-wsgi.py.j2 @@ -46,9 +46,9 @@ if len(sys.argv) > 1: loggingLevel = "DEBUG" # set up some logging -- selectable for diagnostics -logging.basicConfig(filename='{{ nginx_log_dir }}/portal.log',format='%(asctime)s.%(msecs)03d:%(name)s:%(message)s', datefmt='%M:%S',level=loggingLevel) -logger = logging.getLogger('{{ nginx_log_dir }}/portal.log') -handler = RotatingFileHandler("{{ nginx_log_dir }}/portal.log", maxBytes=100000, backupCount=2) +logging.basicConfig(filename='/var/log/uwsgi/app/captiveportal.log',format='%(asctime)s.%(msecs)03d:%(name)s:%(message)s', datefmt='%M:%S',level=loggingLevel) +logger = logging.getLogger('/var/log/uwsgi/app/captiveportal.log') +handler = RotatingFileHandler("/var/log/uwsgi/app/captiveportal.log", maxBytes=100000, backupCount=2) logger.addHandler(handler) PORT={{ captiveportal_port }} From fb377ee29a5a6c915810969d2c11117a40d6c016 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 18 Jan 2020 23:05:25 -0600 Subject: [PATCH 04/16] let /etc/logrotate.d/uwsgi do its job --- roles/2-common/tasks/fl.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/roles/2-common/tasks/fl.yml b/roles/2-common/tasks/fl.yml index 21038dd3d..2676d9b3a 100644 --- a/roles/2-common/tasks/fl.yml +++ b/roles/2-common/tasks/fl.yml @@ -37,14 +37,3 @@ src: "{{ doc_root }}/common/fonts" # /library/www/html path: "{{ doc_root }}/common/webfonts" state: link - -- name: File Layout - Create log file directories {{ apache_log_dir }} & {{ nginx_log_dir }} - file: - path: "{{ item }}" - owner: "{{ apache_user }}" # www-data - group: "{{ apache_user }}" # www-data - mode: '0770' - state: directory - with_items: - - "{{ apache_log_dir }}" # /var/log/apache2 typically, as set in /opt/iiab/iiab/vars/.yml - - "{{ nginx_log_dir }}" # /var/log/nginx From c4dea1b5c22347bd5127eace3c7574e9c8637365 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 18 Jan 2020 23:17:52 -0600 Subject: [PATCH 05/16] clean up uwsgi.service --- roles/nginx/tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml index e5c4c6a18..d2f57ffe3 100644 --- a/roles/nginx/tasks/main.yml +++ b/roles/nginx/tasks/main.yml @@ -3,6 +3,7 @@ path: "{{ item.path }}" state: absent with_items: + - { path: "/etc/systemd/system/uwsgi.service" } - { path: "{{ nginx_config_dir }}/usb-lib.conf" } - { path: "{{ nginx_config_dir }}/modules.conf" } From 643399eb60da14865a7acdc4ed38c13e2cf4b3dd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 19 Jan 2020 01:11:03 -0600 Subject: [PATCH 06/16] remove comment --- roles/captiveportal/tasks/main.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/captiveportal/tasks/main.yml b/roles/captiveportal/tasks/main.yml index 082de91b1..afe1876a9 100644 --- a/roles/captiveportal/tasks/main.yml +++ b/roles/captiveportal/tasks/main.yml @@ -118,8 +118,6 @@ state: restarted daemon_reload: yes -# ABOVE DOES NOT WORK ON UBUNTU 16.04 -- what follows is a crude hack (seems to work!) - - name: Stop 'dnsmasq' systemd service systemd: name: dnsmasq From 23582410a61515b5e146c1126604c6a800639a5c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 19 Jan 2020 01:25:18 -0600 Subject: [PATCH 07/16] move unused files --- ...admin-console-apache.conf => admin-console-apache.conf.unused} | 0 .../{admin-console-nginx.conf => admin-console-nginx.conf.unused} | 0 .../templates/{admin-console.ini => admin-console.ini.unused} | 0 roles/nginx/templates/{uwsgi.service => uwsgi.service.unused} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename roles/nginx/templates/{admin-console-apache.conf => admin-console-apache.conf.unused} (100%) rename roles/nginx/templates/{admin-console-nginx.conf => admin-console-nginx.conf.unused} (100%) rename roles/nginx/templates/{admin-console.ini => admin-console.ini.unused} (100%) rename roles/nginx/templates/{uwsgi.service => uwsgi.service.unused} (100%) diff --git a/roles/nginx/templates/admin-console-apache.conf b/roles/nginx/templates/admin-console-apache.conf.unused similarity index 100% rename from roles/nginx/templates/admin-console-apache.conf rename to roles/nginx/templates/admin-console-apache.conf.unused diff --git a/roles/nginx/templates/admin-console-nginx.conf b/roles/nginx/templates/admin-console-nginx.conf.unused similarity index 100% rename from roles/nginx/templates/admin-console-nginx.conf rename to roles/nginx/templates/admin-console-nginx.conf.unused diff --git a/roles/nginx/templates/admin-console.ini b/roles/nginx/templates/admin-console.ini.unused similarity index 100% rename from roles/nginx/templates/admin-console.ini rename to roles/nginx/templates/admin-console.ini.unused diff --git a/roles/nginx/templates/uwsgi.service b/roles/nginx/templates/uwsgi.service.unused similarity index 100% rename from roles/nginx/templates/uwsgi.service rename to roles/nginx/templates/uwsgi.service.unused From e25604bc6426accb679c30548284fb019916ca48 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 19 Jan 2020 12:14:38 -0600 Subject: [PATCH 08/16] managed by /etc/logrotate.d/uwsgi --- roles/nginx/tasks/install.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/roles/nginx/tasks/install.yml b/roles/nginx/tasks/install.yml index cf7b1f896..d59224e0f 100644 --- a/roles/nginx/tasks/install.yml +++ b/roles/nginx/tasks/install.yml @@ -28,12 +28,6 @@ - { src: 'roles/nginx/templates/nginx.conf.j2', dest: '/etc/nginx/nginx.conf' } - { src: 'roles/nginx/templates/ports.conf.j2', dest: '/etc/{{ apache_service }}/ports.conf' } -- name: Let uwsgi (running as {{ apache_user }}) write log files - file: - path: /var/log/uwsgi/app - state: directory - owner: "{{ apache_user }}" - - name: "Add 'nginx_installed: True' to {{ iiab_state_file }}" lineinfile: dest: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml From d8b08c1f067aa53d6bb8cda2bc0405e3ebc21634 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 19 Jan 2020 21:28:17 -0600 Subject: [PATCH 09/16] always enable uwsgi --- roles/captiveportal/tasks/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/captiveportal/tasks/main.yml b/roles/captiveportal/tasks/main.yml index afe1876a9..36970c291 100644 --- a/roles/captiveportal/tasks/main.yml +++ b/roles/captiveportal/tasks/main.yml @@ -112,11 +112,13 @@ state: absent when: not captiveportal_enabled +# lets assume admin-console was/will be installed anyway - name: Restart uwsgi systemd: name: uwsgi - state: restarted daemon_reload: yes + state: restarted + enabled: true - name: Stop 'dnsmasq' systemd service systemd: From 2acf98af608e123e2d74a3b4ecf1d1c8852e8e13 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 21 Jan 2020 00:23:55 -0600 Subject: [PATCH 10/16] move log directory --- roles/captiveportal/tasks/main.yml | 8 ++++++++ roles/captiveportal/templates/capture-wsgi.py.j2 | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/roles/captiveportal/tasks/main.yml b/roles/captiveportal/tasks/main.yml index 36970c291..5e2c3aff9 100644 --- a/roles/captiveportal/tasks/main.yml +++ b/roles/captiveportal/tasks/main.yml @@ -14,6 +14,14 @@ state: directory owner: "{{ apache_user }}" +- name: Create directory /var/log/captiveportal for logs; set owner to {{ apache_user }} + file: + path: /var/log/captiveportal + state: directory + owner: "{{ apache_user }}" + group: "{{ apache_user }}" + mode: 0750 # same as /var/log/apache2 + - 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 }}" diff --git a/roles/captiveportal/templates/capture-wsgi.py.j2 b/roles/captiveportal/templates/capture-wsgi.py.j2 index 805e79213..9e837f374 100755 --- a/roles/captiveportal/templates/capture-wsgi.py.j2 +++ b/roles/captiveportal/templates/capture-wsgi.py.j2 @@ -46,9 +46,9 @@ if len(sys.argv) > 1: loggingLevel = "DEBUG" # set up some logging -- selectable for diagnostics -logging.basicConfig(filename='/var/log/uwsgi/app/captiveportal.log',format='%(asctime)s.%(msecs)03d:%(name)s:%(message)s', datefmt='%M:%S',level=loggingLevel) -logger = logging.getLogger('/var/log/uwsgi/app/captiveportal.log') -handler = RotatingFileHandler("/var/log/uwsgi/app/captiveportal.log", maxBytes=100000, backupCount=2) +logging.basicConfig(filename='/var/log/captiveprotal/captiveportal.log',format='%(asctime)s.%(msecs)03d:%(name)s:%(message)s', datefmt='%M:%S',level=loggingLevel) +logger = logging.getLogger('/var/log/captiveportal/captiveportal.log') +handler = RotatingFileHandler("/var/log/captiveportal/captiveportal.log", maxBytes=100000, backupCount=2) logger.addHandler(handler) PORT={{ captiveportal_port }} From ab411eda6539d589add6754f8130f138264b87bd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Jan 2020 10:45:14 -0600 Subject: [PATCH 11/16] correct typo in capture-wsgi.py.j2 --- roles/captiveportal/templates/capture-wsgi.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/captiveportal/templates/capture-wsgi.py.j2 b/roles/captiveportal/templates/capture-wsgi.py.j2 index 9e837f374..e240b827a 100755 --- a/roles/captiveportal/templates/capture-wsgi.py.j2 +++ b/roles/captiveportal/templates/capture-wsgi.py.j2 @@ -46,7 +46,7 @@ if len(sys.argv) > 1: loggingLevel = "DEBUG" # set up some logging -- selectable for diagnostics -logging.basicConfig(filename='/var/log/captiveprotal/captiveportal.log',format='%(asctime)s.%(msecs)03d:%(name)s:%(message)s', datefmt='%M:%S',level=loggingLevel) +logging.basicConfig(filename='/var/log/captiveportal/captiveportal.log',format='%(asctime)s.%(msecs)03d:%(name)s:%(message)s', datefmt='%M:%S',level=loggingLevel) logger = logging.getLogger('/var/log/captiveportal/captiveportal.log') handler = RotatingFileHandler("/var/log/captiveportal/captiveportal.log", maxBytes=100000, backupCount=2) logger.addHandler(handler) From eb39494f1800176a729e3ea7a8d5f2b144256b9d Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Jan 2020 14:24:23 -0600 Subject: [PATCH 12/16] handle /etc/init.d/uwsgi behavior --- roles/captiveportal/tasks/main.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/captiveportal/tasks/main.yml b/roles/captiveportal/tasks/main.yml index 5e2c3aff9..87e03de23 100644 --- a/roles/captiveportal/tasks/main.yml +++ b/roles/captiveportal/tasks/main.yml @@ -78,6 +78,11 @@ # enabled: False # when: not captiveportal_enabled +- name: Stop uwsgi + systemd: + name: uwsgi + state: stopped + - name: Install uWSGI config file /etc/uwsgi/apps-enabled/captiveportal.ini from template template: src: captiveportal.ini.j2 @@ -121,11 +126,11 @@ when: not captiveportal_enabled # lets assume admin-console was/will be installed anyway -- name: Restart uwsgi +- name: Start uwsgi systemd: name: uwsgi daemon_reload: yes - state: restarted + state: started enabled: true - name: Stop 'dnsmasq' systemd service From 22bf00d131c0cfdde806044293919671defff3a4 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 22 Jan 2020 17:46:22 -0500 Subject: [PATCH 13/16] Create captiveportal/tasks/install.yml --- roles/captiveportal/tasks/install.yml | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 roles/captiveportal/tasks/install.yml diff --git a/roles/captiveportal/tasks/install.yml b/roles/captiveportal/tasks/install.yml new file mode 100644 index 000000000..5d684e198 --- /dev/null +++ b/roles/captiveportal/tasks/install.yml @@ -0,0 +1,59 @@ +- name: "Download & install packages: python3-dateutil, python3-jinja2" + package: + name: "{{ item }}" + state: present + with_items: + - python3-dateutil + - python3-jinja2 + +- name: mkdir /opt/iiab/captiveportal for scripts & templates, set owner to {{ apache_user }} + file: + path: /opt/iiab/captiveportal + state: directory + owner: "{{ apache_user }}" + +- name: mkdir /var/log/captiveportal for logs, set ownership {{ apache_user }}:{{ apache_user }}, set mode '0750' + file: + path: /var/log/captiveportal + state: directory + owner: "{{ apache_user }}" + group: "{{ apache_user }}" + mode: '0750' # Same as /var/log/apache2 + +- name: "Install 3 scripts from template: /opt/iiab/captiveportal/checkurls, /usr/sbin/iiab-divert-to-nginx, /usr/sbin/iiab-make-cp-servers.py" + 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-divert-to-nginx, dest: /usr/sbin/, mode: '0755' } + - { src: roles/captiveportal/templates/iiab-make-cp-servers.py, dest: /usr/sbin/, mode: '0755' } + +- name: Install /opt/iiab/captiveportal/capture-wsgi.py from template, mode '0755' (creates the server) + template: + src: 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 + - mac.template + +- 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 /opt/iiab/captiveportal/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: "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' From 112a35c6a80040789296139ffc8b4f6a23268621 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 22 Jan 2020 18:05:23 -0500 Subject: [PATCH 14/16] Create captiveportal/tasks/enable-or-disable.yml --- .../captiveportal/tasks/enable-or-disable.yml | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 roles/captiveportal/tasks/enable-or-disable.yml diff --git a/roles/captiveportal/tasks/enable-or-disable.yml b/roles/captiveportal/tasks/enable-or-disable.yml new file mode 100644 index 000000000..504467114 --- /dev/null +++ b/roles/captiveportal/tasks/enable-or-disable.yml @@ -0,0 +1,65 @@ +# 2020-01-22: Package 'uwsgi' is installed by nginx/tasks/install.yml for +# Captive Portal (responds to browsers trying to detect a Captive Portal) and +# also for Admin Console. + +# IIAB makes the 'uwsgi' service mandatory for now (see Line 45) but this could +# perhaps be auto-disabled in future (or never installed?) e.g. if Captive +# Portal + Admin Console are both unneeded...and impact of uWSGI is too high ? + +- name: Stop 'uwsgi' systemd service (may include 3 child processes for Captive Portal, and 3 child processes for Admin Console) + systemd: + name: uwsgi + state: stopped + +- name: Install /etc/uwsgi/apps-enabled/captiveportal.ini from template (if captiveportal_enabled) + template: + src: captiveportal.ini.j2 + dest: /etc/uwsgi/apps-enabled/captiveportal.ini + when: captiveportal_enabled | bool + +- name: Delete /etc/uwsgi/apps-enabled/captiveportal.ini (if not captiveportal_enabled) + file: + path: /etc/uwsgi/apps-enabled/captiveportal.ini + state: absent + when: not captiveportal_enabled + +- name: Symlink /etc/nginx/sites-enabled/capture.conf -> /etc/nginx/sites-available/capture.conf to enable NGINX to service the sites in checkurls list (if captiveportal_enabled) + 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 (if not captiveportal_enabled) + file: + path: /etc/nginx/sites-enabled/capture.conf + state: absent + when: not captiveportal_enabled + +- name: Delete /etc/dnsmasq.d/capture to make sure dnsmasq is not diverting (if not captiveportal_enabled) + file: + path: /etc/dnsmasq.d/capture + state: absent + when: not captiveportal_enabled + +# Let's assume (for now) that Admin Console was/will be installed. Disabling of +# uWSGI's service can be implemented later as nec, e.g. if CP+AC both disabled? +- name: Start & Enable 'uwsgi' systemd service (may include 3 child processes for Captive Portal, and 3 child processes for Admin Console) + systemd: + name: uwsgi + daemon_reload: yes + state: started + enabled: true + +# Unify 2 stanzas below ('state: restarted') when we end Ubuntu 16.04 support. +- name: Stop 'dnsmasq' systemd service (if dnsmasq_enabled) + systemd: + name: dnsmasq + state: stopped + when: dnsmasq_enabled | bool + +- name: Start 'dnsmasq' systemd service (if dnsmasq_enabled) + systemd: + name: dnsmasq + state: started + when: dnsmasq_enabled | bool From 91bb1cdb2f7a1a922cb23807767c5421d8937c9b Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 22 Jan 2020 18:09:13 -0500 Subject: [PATCH 15/16] Modularize & clean captiveportal/tasks/main.yml --- roles/captiveportal/tasks/main.yml | 191 +++++++---------------------- 1 file changed, 44 insertions(+), 147 deletions(-) diff --git a/roles/captiveportal/tasks/main.yml b/roles/captiveportal/tasks/main.yml index 87e03de23..f339c6b3e 100644 --- a/roles/captiveportal/tasks/main.yml +++ b/roles/captiveportal/tasks/main.yml @@ -1,149 +1,46 @@ -# TO DO: move ~7 stanzas below into tasks/install.yml +# "How do i fail a task in Ansible if the variable contains a boolean value? +# I want to perform input validation for Ansible playbooks" +# https://stackoverflow.com/questions/46664127/how-do-i-fail-a-task-in-ansible-if-the-variable-contains-a-boolean-value-i-want/46667499#46667499 -- name: "Download & install packages: python3-dateutil, python3-jinja2" - package: - name: "{{ item }}" - state: present +# If 0-init/tasks/validate_vars.yml has DEFINITELY been run (?) perhaps no need +# to re-check whether vars are defined here. As Ansible vars cannot be unset: +# https://serverfault.com/questions/856729/how-to-destroy-delete-unset-a-variable-value-in-ansible + +- name: Assert that "captiveportal_install is sameas true" (boolean not string etc) + assert: + that: captiveportal_install is sameas true + fail_msg: "PLEASE SET 'captiveportal_install: True' e.g. in: /etc/iiab/local_vars.yml" + quiet: yes + #that: captiveportal_install is defined and captiveportal_install is sameas true + #success_msg: captiveportal_install is defined and captiveportal_install is sameas true + +- name: Assert that "captiveportal_enabled | type_debug == 'bool'" (boolean not string etc) + assert: + that: captiveportal_enabled | type_debug == 'bool' + fail_msg: "PLEASE GIVE VARIABLE 'captiveportal_enabled' A PROPER (UNQUOTED) BOOLEAN VALUE e.g. in: /etc/iiab/local_vars.yml" + quiet: yes + #that: captiveportal_enabled is defined and captiveportal_enabled | type_debug == 'bool' + #success_msg: captiveportal_enabled is defined and captiveportal_enabled | type_debug == 'bool' + +- name: Install Captive Portal if 'captiveportal_installed' is not defined in {{ iiab_state_file }} # /etc/iiab/iiab_state.yml + include_tasks: install.yml + when: captiveportal_installed is undefined + +- name: Enable or Disable Captive Portal + include_tasks: enable-or-disable.yml + +- name: Add 'captiveportal' variable values to {{ iiab_ini_file }} + ini_file: + path: "{{ iiab_ini_file }}" + section: captiveportal + option: "{{ item.option }}" + value: "{{ item.value | string }}" 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: Create directory /var/log/captiveportal for logs; set owner to {{ apache_user }} - file: - path: /var/log/captiveportal - state: directory - owner: "{{ apache_user }}" - group: "{{ apache_user }}" - mode: 0750 # same as /var/log/apache2 - -- 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: Stop uwsgi - systemd: - name: uwsgi - state: stopped - -- 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: Start uwsgi - systemd: - name: uwsgi - daemon_reload: yes - state: started - 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 + - option: name + value: Captive Portal + - option: description + value: '"Captive Portal tries to open the browser automatically, so users don''t have to type in URL''s like http://box.lan in support of kiosk-like situations, in multilingual and less literate communities."' + - option: installed + value: "{{ captiveportal_install }}" + - option: enabled + value: "{{ captiveportal_enabled }}" From af27f90c04d71431c98aa2ee02e0c50a2d2ac238 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 22 Jan 2020 18:20:25 -0500 Subject: [PATCH 16/16] Indent nodejs/tasks/main.yml --- roles/nodejs/tasks/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/nodejs/tasks/main.yml b/roles/nodejs/tasks/main.yml index 86e318a44..95b17d8e3 100644 --- a/roles/nodejs/tasks/main.yml +++ b/roles/nodejs/tasks/main.yml @@ -81,10 +81,10 @@ - name: Install latest Node.js {{ nodejs_version }} which includes /usr/bin/npm (debuntu) package: - # name: nodejs={{ nodejs_version }} - name: nodejs - state: latest - # state: present + #name: nodejs={{ nodejs_version }} + name: nodejs + state: latest + #state: present when: internet_available and is_debuntu #when: internet_available and (is_debian_8 or is_debian_9 or is_ubuntu_16 or is_ubuntu_17)