- 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 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: Restart & Enable 'uwsgi-captiveportal' systemd service (uWSGI server) that responds to browsers trying to detect a Captive Portal systemd: name: uwsgi-captiveportal.service 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.service state: stopped enabled: False 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 - 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' #- name: Restart dnsmasq # systemd: # name: dnsmasq # state: restarted # when: dnsmasq_enabled | bool # 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 state: stopped when: dnsmasq_enabled | bool - name: Start 'dnsmasq' systemd service systemd: name: dnsmasq state: started when: dnsmasq_enabled | bool