if node['ephemeral_lvm']['enabled']

  mount_point = node['ephemeral_lvm']['mount_point']
  owner = node['ephemeral_lvm']['owner'] || 'root'
  group = node['ephemeral_lvm']['group'] || 'root'
  folders = node['ephemeral_lvm']['folders']

  user owner do
    shell '/sbin/nologin'
    only_if { owner }
  end

  group group do
    members owner
    append true
    only_if { group }
  end

  # Why is xvdb and xvdc there?
  %w(xvdb xvdc).each do |drive|
    execute "unmount-#{drive}" do
      command "umount -f /dev/#{drive}"
      returns [0, 32]
    end
    delete_lines "remove-#{drive}-from-fstab" do
      path '/etc/fstab'
      pattern drive
    end
  end

  directory mount_point do
    owner owner
    group group
    mode '0755'
    recursive true
    action :create
  end

  include_recipe 'ephemeral_lvm::default'

  if folders
    folders.each do |folder_name, folder_attrs|
      mode = folder_attrs['mode'] || '0755'
      force_chown = folder_attrs['force_chown']

      directory folder_name do
        owner owner
        group group
        mode mode
        recursive true
        action :create
      end

      execute "force-#{folderName}-ownership" do
        command "chown -R #{owner}:#{group} #{folderName}"
        only_if { force_chown }
      end
    end
  end
end
