From 2beeefa3dd29b34245aa7c55d7fb5c6fe5f200c1 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Tue, 19 Dec 2017 16:11:49 +0100 Subject: [PATCH] Improve handling of mountpoints --- defaults/main.yml | 3 +++ tasks/files.yml | 31 +++++++------------------- tasks/install.yml | 13 +++++++++++ tasks/mountpoints.yml | 52 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 tasks/mountpoints.yml diff --git a/defaults/main.yml b/defaults/main.yml index 2b7728e..b67dbc3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,3 +28,6 @@ drupal_post_deploy_tasks: letsencrypt_pause_services: - 'apache2' + +fstype_convert: + btrfs: 'btrfs-convert --no-progress {{ item.src }}' diff --git a/tasks/files.yml b/tasks/files.yml index e1d1dce..9cfc390 100644 --- a/tasks/files.yml +++ b/tasks/files.yml @@ -6,29 +6,14 @@ src='{{ relativeRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' dest='{{ drupalRoot }}/sites/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' -- block: - - - name: "Ensure mounted and webroot file directory" - file: - dest='{{ item }}' - state='directory' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='755' - with_items: - - '{{ drupal_domain.0.mountpoint }}' - - '{{ webRoot }}/files' - ignore_errors: yes - - - name: "Link webroot to mounted directory" - file: - src='{{ drupal_domain.0.mountpoint }}/{{ drupal_domain.0.shortname|default("default") }}' - dest='{{ webRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}' - state='link' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='755' - +- name: "Link webroot to mounted directory" + file: + src='{{ drupal_domain.0.mountpoint }}/{{ drupal.id }}/{{ drupal_domain.0.shortname|default("default") }}' + dest='{{ webRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}' + state='link' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='755' when: drupal_domain.0.mountpoint is defined - name: "Ensure File Directories" diff --git a/tasks/install.yml b/tasks/install.yml index 15176c6..084888d 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -117,6 +117,19 @@ with_items: '{{ drupal.domains }}' when: item.install|default(true) +- name: "Ensure Files Directory" + file: + path='{{ webRoot }}/files' + state='directory' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='775' + when: drupal.install_extra_dirs|default(true) + +- include_tasks: mountpoints.yml + with_items: '{{ drupal.mountpoints|default[] }}' + when: drupal.install_extra_dirs|default(true) + - include_tasks: files.yml with_nested: - '{{ drupal.domains }}' diff --git a/tasks/mountpoints.yml b/tasks/mountpoints.yml new file mode 100644 index 0000000..dd7ba23 --- /dev/null +++ b/tasks/mountpoints.yml @@ -0,0 +1,52 @@ +--- +# file: roles/drupal/tasks/mountpoints.yml + +- name: "Check File System Type" + shell: 'lsblk --noheadings --fs --output FSTYPE {{ item.src }}' + register: fstype + +- name: "Convert File System Type" + shell: '{{ fstype_convert[item.fstype] }}' + when: item.fstype != fstype + +- name: "Ensure directory for mountpoint" + file: + dest: '{{ item.path }}' + state: 'directory' + owner: '{{ apacheUser }}' + group: '{{ apacheUser }}' + mode: '755' + +- name: "Ensure directory for mountpoint in jail" + file: + dest: '{{ jailroot }}/{{ drupal.jail.name }}{{ item.path }}' + state: 'directory' + owner: '{{ apacheUser }}' + group: '{{ apacheUser }}' + mode: '755' + when: drupal.jail is defined + +- name: "Mount the item" + mount: + path: '{{ item.path }}' + src: '{{ item.src }}' + fstype: '{{ item.fstype }}' + opts: '{{ item.opts|default(omit) }}' + state: 'mounted' + +- name: "Mount the item in jail" + mount: + path: '{{ jailroot }}/{{ drupal.jail.name }}{{ item.path }}' + src: '{{ item.src }}' + fstype: '{{ item.fstype }}' + opts: '{{ item.opts|default(omit) }}' + state: 'mounted' + when: drupal.jail is defined + +- name: "Ensure file directory in mountpoint" + file: + dest: '{{ item.path }}/{{ drupal.id }}' + state: 'directory' + owner: '{{ apacheUser }}' + group: '{{ apacheUser }}' + mode: '755' -- GitLab