Roots Discourse

Adding a block storage volume to server at D.O

I need to add a block storage in a droplet provisioned with Trellis. As far as I know, this block is mounted as a HD. So, is it possible to tell Trellis that must use it as normal storage for bedrock projects inside?

Thank you!

Are you wanting to use block storage for the entire Bedrock project or just the uploads?

This is what I’m using for DO’s block storage to handle the uploads folder (props to @QWp6t):

# roles/wordpress-setuptasks/main.yml

...

- block:
  - name: Check if block storage volume is mounted
    shell: "mountpoint -q {{ www_root }}/{{ item.key }}/shared/storage"
    with_dict: "{{ wordpress_sites }}"
    register: block_storage_volume_mounted
    changed_when: block_storage_volume_mounted.rc != 0
    failed_when: false

  - name: Check if block storage volume is present
    shell: "lsblk | grep -q {{ www_root }}/{{ item.key }}/shared/storage"
    with_dict: "{{ wordpress_sites }}"
    register: block_storage_volume_exists
    changed_when: block_storage_volume_exists.rc != 0
    failed_when: false

  - block:
    - name: Create block storage volume
      digital_ocean_block_storage:
        state: present
        command: create
        api_token: "{{ digitalocean_api_key }}"
        region: nyc3
        block_size: 30
        volume_name: "{{ item.key | replace('.', '-') }}-{{ env }}"
      with_dict: "{{ wordpress_sites }}"

    - name: Detach block storage volume
      digital_ocean_block_storage:
        state: absent
        command: attach
        api_token: "{{ digitalocean_api_key }}"
        region: nyc3
        droplet_id: "{{ digitalocean_droplet }}"
        volume_name: "{{ item.key | replace('.', '-') }}-{{ env }}"
      with_dict: "{{ wordpress_sites }}"

    - name: Attach block storage volume
      digital_ocean_block_storage:
        state: present
        command: attach
        api_token: "{{ digitalocean_api_key }}"
        region: nyc3
        droplet_id: "{{ digitalocean_droplet }}"
        volume_name: "{{ item.key | replace('.', '-') }}-{{ env }}"
      with_dict: "{{ wordpress_sites }}"

    - name: Format block storage volume
      filesystem:
        fstype: ext4
        force: no
        dev: "/dev/disk/by-id/scsi-0DO_Volume_{{ item.key | replace('.', '-') }}-{{ env }}"
        resizefs: yes
      with_dict: "{{ wordpress_sites }}"
    when: block_storage_volume_exists is failed

  - name: Unmount block storage volume
    mount:
      name: "{{ www_root }}/{{ item.key }}/shared/storage"
      state: unmounted
    with_dict: "{{ wordpress_sites }}"
    when: block_storage_volume_mounted is success and block_storage_volume_exists is failed

  - name: Mount block storage volume
    mount:
      name: "{{ www_root }}/{{ item.key }}/shared/storage"
      src: "/dev/disk/by-id/scsi-0DO_Volume_{{ item.key | replace('.', '-') }}-{{ env }}"
      fstype: ext4
      state: mounted
      boot: yes
      opts: defaults,nofail,discard
    with_dict: "{{ wordpress_sites }}"

  - name: "Set POSIX permissions for {{ web_user }}:{{ web_group }} in block storage"
    file:
      path: "{{ www_root }}/{{ item.key }}/shared/storage"
      owner: "{{ web_user }}"
      group: "{{ web_group }}"
      mode: "u=rwX,g=rX,o=rX"
      recurse: yes
      state: directory
    with_dict: "{{ wordpress_sites }}"

  - name: Create uploads folder
    file:
      state: directory
      path: "{{ www_root }}/{{ item.key }}/shared/storage/uploads"
    with_dict: "{{ wordpress_sites }}"
  when: env != 'development'

# group_vars/all/main.yml
...

digitalocean_api_key: "{{ vault_digitalocean_api_key }}" # Defined in group_vars/all/vault.yml
# roles/deploy/defaults/main.yml

project_shared_children:
  - path: web/app/uploads
    src: storage/uploads
7 Likes

That sounds good. Thank you. I will try it.

Where is the digitalocean_droplet value coming from?

BTW, I’m fairly new to Trellis in general (LOVE IT!), and completely new to anything deeper than the basic docs (this is my first time digging deeper than wordpress_sites.yml, vault.yml, hosts, etc). So, if you have any additional advice for this particular of deep dig (storing images in DO Spaces), please do share.

Late to the party, but digitalocean_droplet is the ID of the droplet you created for Trellis. I define it in vault.yml.