LOC-18 Deploy server with ansible
LOC-18 Deploy server with ansible

It could do with some tidying and some conditionals, but it's now possible to deploy the server with the ansible playbook.

file:a/README.md -> file:b/README.md
--- a/README.md
+++ b/README.md
@@ -12,6 +12,11 @@
 The provided client uses basic End To End encryption (currently using PGP as the encryption mechanism), and the server holds encrypted payloads in memory only (to ensure the ciphertext doesn't end up captured on the hosting provider's SAN for a time). Message payloads are purged after a short interval to help reduce the potential exposure were someone to be monitoring the server's memory.
 
 The default behaviour is a Multi-User Chat (MUC), however direct messaging between participants within a room is also supported.
+
+
+## Project Management
+
+Planned features, bugfixes etc can all be viewed at [project.bentasker.co.uk](https://projects.bentasker.co.uk/jira_projects/browse/LOC.html). Release notes are at [bentasker.co.uk](https://www.bentasker.co.uk/documentation/release-notes/91-localchat)
 
 
 

file:b/ansible/README.md (new)
--- /dev/null
+++ b/ansible/README.md
@@ -1,1 +1,9 @@
+LocalChat Ansible Playbook Instructions
+=========================================
 
+
+
+Dependancies
+----------------
+
+Requires ansible >= 2.2

--- /dev/null
+++ b/ansible/group_vars/localchat-servers.yml
@@ -1,1 +1,3 @@
+ansible_user: ansible
+ansible_become: true
 

--- /dev/null
+++ b/ansible/inventory/hosts
@@ -1,1 +1,4 @@
+[localchat-servers]
+192.168.7.253
 
+

--- /dev/null
+++ b/ansible/locaLchat.service
@@ -1,1 +1,15 @@
+[Unit]
+Description=LocalChat
+After=multi-user.target
 
+[Service]
+WorkingDirectory=/usr/local/localchat
+Type=idle
+ExecStart=/usr/bin/python LocalChat.py
+Restart=always
+RestartSec=3
+
+[Install]
+WantedBy=multi-user.target
+
+

--- /dev/null
+++ b/ansible/localchat-servers.retry
@@ -1,1 +1,2 @@
+192.168.7.253
 

--- /dev/null
+++ b/ansible/localchat-servers.yml
@@ -1,1 +1,7 @@
+---
 
+-   hosts: localchat-servers
+    roles:
+        - localchat-server
+
+

--- /dev/null
+++ b/ansible/roles/localchat-server/defaults/main.yml
@@ -1,1 +1,4 @@
+localchat_server_install_path: /usr/local/src/localchat
+localchat_server_install_ver: 0.0.2.1
 
+

--- /dev/null
+++ b/ansible/roles/localchat-server/handlers/main.yml
@@ -1,1 +1,14 @@
+---
 
+# Handlers
+
+
+
+- name: Start service
+  # See above.
+  command: systemctl start localchat.service
+
+- name: reload systemd
+  command: systemctl daemon-reload
+
+

--- /dev/null
+++ b/ansible/roles/localchat-server/tasks/main.yml
@@ -1,1 +1,46 @@
+---
 
+- name: Install Utils
+  apt: name={{item}} state=installed
+  with_items:
+    - python-pip
+    - python-sqlite
+    - unzip
+  tags: deps
+
+- name: Install Python Dependancies
+  pip: name={{item}} state=present
+  with_items:
+    - flask
+    - werkzeug
+    - bcrypt
+    - gnupg
+    - pyopenssl
+  tags: deps
+
+
+- name: Create install dir
+  file: path={{localchat_server_install_path}} state=directory
+  
+- name: Download and install Server
+  unarchive:
+    src: "https://github.com/bentasker/LocalChat/archive/v{{localchat_server_install_ver}}.zip"
+    dest: "{{localchat_server_install_path}}"
+    remote_src: yes
+  
+- name: Symlink latest
+  file:
+    src: "{{localchat_server_install_path}}/LocalChat-{{localchat_server_install_ver}}/server/LocalChat.py"
+    dest: "{{localchat_server_install_path}}/LocalChat.py"
+    state: link
+    
+- name: Create Unit File
+  template: src=localchat.service dest=/etc/systemd/system/localchat.service
+  notify: reload systemd
+
+
+- name: Start server
+  command: systemctl start localchat
+
+
+

--- /dev/null
+++ b/ansible/roles/localchat-server/templates/localchat.service
@@ -1,1 +1,14 @@
+[Unit]
+Description=LocalChat
+After=multi-user.target
 
+[Service]
+WorkingDirectory={{localchat_server_install_path}}
+Type=idle
+ExecStart=/usr/bin/python LocalChat.py
+Restart=always
+RestartSec=3
+
+[Install]
+WantedBy=multi-user.target
+

file:b/ansible/site.yml (new)
--- /dev/null
+++ b/ansible/site.yml
@@ -1,1 +1,2 @@
+- include: localchat-servers.yml
 

--- a/server/LocalChat.py
+++ b/server/LocalChat.py
@@ -758,7 +758,7 @@
         
         '''
 
-        crypted = self.gpg.encrypt(msg,None,passphrase=self.syskey,symmetric="AES256",armor=False)
+        crypted = self.gpg.encrypt(msg,None,passphrase=self.syskey,symmetric="AES256",armor=False,encrypt=False)
         return crypted.data.encode('base64')
 
 
@@ -821,5 +821,5 @@
     #
     # This will likely become a CLI argument later
     port = int(os.environ.get('PORT', 8090))
-    app.run(host='127.0.0.1', port=port,debug=True,ssl_context='adhoc')
-
+    app.run(host='127.0.0.1', port=port,ssl_context='adhoc',threaded=False)
+