diff --git a/roles/koillection/tasks/api.yml b/roles/koillection/tasks/api.yml new file mode 100644 index 0000000..bd6cb5d --- /dev/null +++ b/roles/koillection/tasks/api.yml @@ -0,0 +1,23 @@ +--- + +- name: Create API config dir + ansible.builtin.file: + state: directory + dest: "{{ koillection_data_home }}/config/jwt" + owner: www-data + group: www-data + mode: "0o750" + +- name: Link JWT config dir + ansible.builtin.file: + state: link + src: "{{ koillection_data_home }}/config/jwt" + dest: "{{ koillection_app_home }}/config/jwt" + +- name: Run lexik jwt + become: true + become_user: www-data + ansible.builtin.command: + cmd: "php bin/console lexik:jwt:generate-keypair" + chdir: "{{ koillection_app_home }}" + creates: "{{ koillection_app_home }}/config/jwt/private.pem" diff --git a/roles/koillection/tasks/main.yml b/roles/koillection/tasks/main.yml index 41f17ac..4be1e76 100644 --- a/roles/koillection/tasks/main.yml +++ b/roles/koillection/tasks/main.yml @@ -3,10 +3,16 @@ - name: Init db ansible.builtin.include_tasks: db.yml -- name: Create application directory +## Remove the previous app & install the new version +- name: Remove Koillection previous version + ansible.builtin.file: + state: absent + dest: "{{ koillection_app_home }}" + +- name: Create app home ansible.builtin.file: state: directory - dest: "{{ koillection_home }}" + dest: "{{ koillection_app_home }}" owner: root group: www-data mode: "0o750" @@ -15,19 +21,17 @@ ansible.builtin.unarchive: remote_src: true src: "{{ koillection_url }}" - dest: "{{ koillection_home }}" + dest: "{{ koillection_app_home }}" owner: root group: www-data mode: "a-rwx,u+rwX,g+rX" extra_opts: ['--strip-components=1'] - exclude: - - .env - - config/jwt + exclude: "{{ koillection_userdata_app_dirs }}" - name: Put config file ansible.builtin.template: src: "env.j2" - dest: "{{ koillection_home }}/.env" + dest: "{{ koillection_app_home }}/.env" owner: root group: www-data mode: "0o640" @@ -35,21 +39,45 @@ - name: Check writable dirs ansible.builtin.file: state: directory - dest: "{{ koillection_home }}/{{ item }}" + dest: "{{ koillection_app_home }}/{{ item }}" owner: root group: www-data mode: "g+w" recurse: true - loop: - - "var" - - "config/jwt" - - "public/uploads" - - "public/tmp" + loop: "{{ koillection_writable_app_dirs }}" -- name: Run lexik jwt - become: true - become_user: www-data - ansible.builtin.command: - cmd: "php bin/console lexik:jwt:generate-keypair" - chdir: "{{ koillection_home }}" - creates: "{{ koillection_home }}/config/jwt/private.pem" +## Ensure the data dirs exist, populate them if not +- name: Create data home + ansible.builtin.file: + state: directory + path: "{{ koillection_data_home }}" + owner: www-data + group: www-data + mode: "0o750" + +- name: Get data dir + ansible.builtin.stat: + path: "{{ koillection_data_home }}/{{ koillection_userdata_app_dirs[0] }}" + register: _koillection_userdata_dir_stat + +- name: Install Koillection data dir + ansible.builtin.unarchive: + remote_src: true + src: "{{ koillection_url }}" + dest: "{{ koillection_data_home }}" + owner: www-data + group: www-data + mode: "a-rwx,u+rwX,g+rX" + extra_opts: ['--strip-components=1'] + include: "{{ koillection_userdata_app_dirs | map('regex_replace', '^', 'public/') }}" + when: not _koillection_userdata_dir_stat.stat.exists + +- name: Link Koillection userdata dirs + ansible.builtin.file: + state: link + src: "{{ koillection_data_home }}/{{ item }}" + dest: "{{ koillection_app_home }}/{{ item }}" + loop: "{{ koillection_userdata_app_dirs }}" + +- name: Include API activation task + ansible.builtin.include_tasks: api.yml diff --git a/roles/koillection/vars/main.yml b/roles/koillection/vars/main.yml index 4827f94..8c22650 100644 --- a/roles/koillection/vars/main.yml +++ b/roles/koillection/vars/main.yml @@ -5,4 +5,13 @@ koillection_url: "https://giteu.be/koillection/koillection/releases/download/{{ koillection_access_url: "{{ web_hostname | selectattr('type', 'defined') | selectattr('type', '==', 'koillection') | map(attribute='host') | first }}" -koillection_home: "/srv/http/{{ koillection_access_url }}" +# Access path +koillection_app_home: "/var/www/{{ koillection_access_url }}" +koillection_data_home: "/srv/www-data/{{ koillection_access_url }}" + +# App dirs +koillection_writable_app_dirs: + - var + - public/tmp +koillection_userdata_app_dirs: + - public/uploads diff --git a/roles/nginx/templates/vhosts/koi.libertus.eu.conf.j2 b/roles/nginx/templates/vhosts/koi.libertus.eu.conf.j2 index 4ca85a8..0c1486b 100644 --- a/roles/nginx/templates/vhosts/koi.libertus.eu.conf.j2 +++ b/roles/nginx/templates/vhosts/koi.libertus.eu.conf.j2 @@ -1,7 +1,7 @@ server { {% include './templates/header.conf.j2' %} - root /srv/http/koi.libertus.eu/public; + root /var/www/koi.libertus.eu/public; index index.html index.htm index.php;