---
 - name: Install python-webssh
   become: yes
   package:
     name: python-webssh
     state: present

 - name: Standardize the servicefile
   become: yes
   register: servicefile
   copy:
     src: cyberbrain.service
     dest: /usr/lib/systemd/system/cyberbrain.service
     owner: root
     group: root
     mode: 0644

 - name: Ensure default webssh service file is off.
   become: yes
   service:
     name: webssh
     state: stopped
     enabled: no

 - systemd:
     daemon_reload: true
   when: servicefile.changed
   become: yes

 - name: Ensure service is restarted
   when: servicefile.changed
   become: yes
   service:
     name: cyberbrain.service
     enabled: yes
     state: started

 - name: Ensure service is started
   when: not servicefile.changed
   become: yes
   service:
     name: cyberbrain.service
     enabled: yes
     state: started

 - name: Add the webserver conf file
   become: yes
   register: webserver_conf
   copy:
     src: cyberbrain.conf
     dest: /opt/openresty/nginx/conf.d/cyberbrain.conf
     owner: root
     group: http
     mode: 0750

 - name: Ensure the password file is seeded
   become: yes
   template:
     src: cyberbrain.htpasswd.j2
     dest: /opt/openresty/nginx/passwords/cyberbrain.htpasswd
     owner: root
     group: http
     mode: 0750

 - name: Reload openresty
   become: yes
   when: webserver_conf.changed
   service:
     name: openresty.service
     state: reloaded

