# Copyright 2017-present Open Networking Foundation
#
# Licensed 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: The glusterfs registry volume is created
  gluster_volume:
    bricks: "{{ barrier_fs_dir }}/reg_brick1"
    force: true
    cluster: "{{groups.cluster | join(\",\")}}"
    replicas: 3
    name: registry_volume
    state: present
  run_once: true

- name: The glusterfs logging volume is created
  gluster_volume:
    bricks: "{{ barrier_fs_dir }}/log_brick1"
    force: true
    cluster: "{{groups.cluster | join(\",\")}}"
    disperses: 3
    name: logging_volume
    state: present
  run_once: true

- name: Start the gluster volumes
  gluster_volume:
    name: "{{ item }}"
    state: started
  with_items:
    - registry_volume
    - logging_volume

- name: The replicated registry filesystem is mounted
  mount:
    path: "{{ target_voltha_dir }}/registry_data"
    src: "{{ inventory_hostname }}:/registry_volume"
    fstype: glusterfs
    opts:  "defaults,_netdev,noauto,x-systemd.automount"
    state: mounted
  when: target == "cluster"

- name: The replicated logging filesystem is mounted on boot
  mount:
    path: "/var/log/voltha"
    src: "{{ inventory_hostname }}:/logging_volume"
    fstype: glusterfs
    opts:  "defaults,_netdev,noauto,x-systemd.automount"
    state: mounted
  when: target == "cluster"
  tags: [cluster_host]
