diff --git a/roles/matrix_synapse_admin/defaults/main.yml b/roles/matrix_synapse_admin/defaults/main.yml new file mode 100644 index 0000000..56edd62 --- /dev/null +++ b/roles/matrix_synapse_admin/defaults/main.yml @@ -0,0 +1,24 @@ +--- + +# Version to deploy +synadm_version: 0.8.3 +# URL of the tarball +synadm_archive_url: https://github.com/Awesome-Technologies/synapse-admin/releases/download/{{ synadm_version }}/synapse-admin-{{ synadm_version }}.tar.gz +# Expected sha1 of the archive +synadm_archive_sha1: f74676ec618b664d2409032d10c15c1f310222fc + +# Shoulad ansible handle upgrades, or just initial install ? +synadm_manage_upgrade: True + +# Root dir where synadm will be installed +synadm_root_dir: /opt/matrix/synapse_admin + +# Should a web alilas be created, eg set it to synadm to access it from https://yourserver/synadm +# If an alias is not defined (or set to False), you'll have to create a virtualhost pointing at {{ synadm_root_dir }}/web +synadm_web_alias: synadm + +# Optional list of allowed IP address. If undefined, everyone can access it +# synadm_src_ip: +# - 12.13.14.15 +# - 16.17.18.19 + diff --git a/roles/matrix_synapse_admin/meta/main.yml b/roles/matrix_synapse_admin/meta/main.yml new file mode 100644 index 0000000..8360d69 --- /dev/null +++ b/roles/matrix_synapse_admin/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: httpd_common diff --git a/roles/matrix_synapse_admin/tasks/archive_post.yml b/roles/matrix_synapse_admin/tasks/archive_post.yml new file mode 100644 index 0000000..de7547c --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/archive_post.yml @@ -0,0 +1,7 @@ +--- + +- import_tasks: ../includes/webapps_compress_archive.yml + vars: + - root_dir: "{{ synadm_root_dir }}" + - version: "{{ synadm_current_version }}" + tags: matrix diff --git a/roles/matrix_synapse_admin/tasks/archive_pre.yml b/roles/matrix_synapse_admin/tasks/archive_pre.yml new file mode 100644 index 0000000..cc401a9 --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/archive_pre.yml @@ -0,0 +1,7 @@ +--- + +- import_tasks: ../includes/webapps_archive.yml + vars: + - root_dir: "{{ synadm_root_dir }}" + - version: "{{ synadm_current_version }}" + tags: matrix diff --git a/roles/matrix_synapse_admin/tasks/cleanup.yml b/roles/matrix_synapse_admin/tasks/cleanup.yml new file mode 100644 index 0000000..a69f4a3 --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/cleanup.yml @@ -0,0 +1,9 @@ +--- + +- name: Remove temp files + file: path={{ synadm_root_dir }}/tmp/{{ item }} state=absent + loop: + - synapse-admin-{{ synadm_version }}.tar.gz + - synapse-admin-{{ synadm_version }} + tags: matrix + diff --git a/roles/matrix_synapse_admin/tasks/conf.yml b/roles/matrix_synapse_admin/tasks/conf.yml new file mode 100644 index 0000000..d0ea2ab --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/conf.yml @@ -0,0 +1,6 @@ +--- + +- name: Deploy httpd configuration + template: src=httpd.conf.j2 dest=/etc/httpd/ansible_conf.d/10-synadm.conf + notify: reload httpd + tags: matrix diff --git a/roles/matrix_synapse_admin/tasks/directories.yml b/roles/matrix_synapse_admin/tasks/directories.yml new file mode 100644 index 0000000..753fc4b --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/directories.yml @@ -0,0 +1,12 @@ +--- + +- name: Create directory structure + file: path={{ synadm_root_dir }}/{{ item.dir }} state=directory owner={{ item.owner | default(omit) }} group={{ item.group | default(omit) }} mode={{ item.mode | default(omit) }} + with_items: + - dir: tmp + - dir: archives + mode: 700 + - dir: meta + mode: 700 + - dir: web + tags: matrix diff --git a/roles/matrix_synapse_admin/tasks/facts.yml b/roles/matrix_synapse_admin/tasks/facts.yml new file mode 100644 index 0000000..65d2c60 --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/facts.yml @@ -0,0 +1,10 @@ +--- + +- block: + - import_tasks: ../includes/webapps_set_install_mode.yml + vars: + - root_dir: "{{ synadm_root_dir }}" + - version: "{{ synadm_version }}" + - set_fact: synadm_install_mode={{ (install_mode == 'upgrade' and not synadm_manage_upgrade) | ternary('none',install_mode) }} + - set_fact: synadm_current_version={{ current_version | default('') }} + tags: matrix diff --git a/roles/matrix_synapse_admin/tasks/install.yml b/roles/matrix_synapse_admin/tasks/install.yml new file mode 100644 index 0000000..a61e20b --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/install.yml @@ -0,0 +1,24 @@ +--- + +- when: synadm_install_mode != 'none' + block: + - name: Download Synapse Admin + get_url: + url: "{{ synadm_archive_url }}" + dest: "{{ synadm_root_dir }}/tmp/" + checksum: "sha1:{{ synadm_archive_sha1 }}" + + - name: Extract archive + unarchive: + src: "{{ synadm_root_dir }}/tmp/synapse-admin-{{ synadm_version }}.tar.gz" + dest: "{{ synadm_root_dir }}/tmp/" + remote_src: True + + - name: Move the content to the final top directory + synchronize: + src: "{{ synadm_root_dir }}/tmp/synapse-admin-{{ synadm_version }}/" + dest: "{{ synadm_root_dir }}/web/" + recursive: True + delete: True + delegate_to: "{{ inventory_hostname }}" + tags: matrix diff --git a/roles/matrix_synapse_admin/tasks/main.yml b/roles/matrix_synapse_admin/tasks/main.yml new file mode 100644 index 0000000..17bda5f --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/main.yml @@ -0,0 +1,13 @@ +--- + +- include: directories.yml +- include: facts.yml +- include: archive_pre.yml + when: synadm_install_mode == 'upgrade' +- include: install.yml +- include: conf.yml +- include: archive_post.yml + when: synadm_install_mode == 'upgrade' +- include: write_version.yml +- include: cleanup.yml + diff --git a/roles/matrix_synapse_admin/tasks/write_version.yml b/roles/matrix_synapse_admin/tasks/write_version.yml new file mode 100644 index 0000000..e9a3d4f --- /dev/null +++ b/roles/matrix_synapse_admin/tasks/write_version.yml @@ -0,0 +1,7 @@ +--- + +- import_tasks: ../includes/webapps_post.yml + vars: + - root_dir: "{{ synadm_root_dir }}" + - version: "{{ synadm_version }}" + tags: matrix diff --git a/roles/matrix_synapse_admin/templates/httpd.conf.j2 b/roles/matrix_synapse_admin/templates/httpd.conf.j2 new file mode 100644 index 0000000..2448d51 --- /dev/null +++ b/roles/matrix_synapse_admin/templates/httpd.conf.j2 @@ -0,0 +1,14 @@ +{% if synadm_web_alias is defined and synadm_web_alias != False %} +Alias /{{ synadm_web_alias }} {{ synadm_root_dir }}/web +{% else %} +# No alias defined, create a vhost to access it +{% endif %} + + AllowOverride None + Options None +{% if synadm_src_ip is defined %} + Require ip {{ synadm_src_ip | join(' ') }} +{% else %} + Require all granted +{% endif %} + diff --git a/roles/matrix_synapse_admin/templates/perms.sh.j2 b/roles/matrix_synapse_admin/templates/perms.sh.j2 new file mode 100644 index 0000000..6cd160c --- /dev/null +++ b/roles/matrix_synapse_admin/templates/perms.sh.j2 @@ -0,0 +1,5 @@ +#!/bin/sh + +chown -R root:root {{ synadm_root_dir }} +find {{ synadm_root_dir }}/web -type f -exec chmod 644 "{}" \; +find {{ synadm_root_dir }}/web -type d -exec chmod 755 "{}" \;