#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

- name: "ec2 - unmount default drive at /mnt"
  mount: name=/mnt src=/dev/xvdb fstype=auto state=unmounted
- name: "ec2 - unmount all ephemeral"
  mount: name={{ item.0 }} src={{ item.1 }} fstype=auto state=unmounted
  when: force_format == 'yes'
  with_together:
    - "{{ node_type_map[node_type].mounts }}"
    - "{{ node_type_map[node_type].devices }}"
- name: "ec2 - format drives"
  filesystem: fstype={{ fstype }} dev={{ item }} force={{ force_format }}
  with_items: "{{ node_type_map[node_type].devices }}"
- name: "ec2 - mount drives"
  mount: name={{ item.0 }} src={{ item.1 }} fstype=auto state=mounted
    opts=defaults,nofail,noatime,nodiratime,comment=cloudconfig passno=2
  with_together:
    - "{{ node_type_map[node_type].mounts }}"
    - "{{ node_type_map[node_type].devices }}"
- name: "ec2 - ensure drives are owned by cluster user"
  file: path={{ item }} state=directory owner={{ cluster_user }} group={{ cluster_group }}
  with_items: "{{ node_type_map[node_type].mounts }}"
