---
- name: Ensure squirro directory exists in shared drive
  ansible.builtin.file:
    path: "{{ item }}"
    group: squirro
    mode: "0755"
    owner: root
    state: directory
  loop:
    - /flash/octopus
    - /flash/squirro
    - /flash/squirro/var
    - /flash/squirro/var/lib
    - /flash/squirro/var/lib/squirro
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro machine learning directory exists in shared drive
  ansible.builtin.file:
    path: "/flash/squirro/var/lib/squirro/{{ item }}"
    group: squirro
    mode: "0755"
    owner: sqtopic
    state: directory
  loop:
    - machinelearning
    - machinelearning/job_logs
    - machinelearning/pretrained_models
    - machinelearning/sentence_splitter
    - machinelearning/templates
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro temp directory exists in shared drive
  ansible.builtin.file:
    path: /flash/squirro/var/lib/squirro/temp
    group: squirro
    mode: "0755"
    owner: sqtopic
    state: directory
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro storage directory exists in shared drive
  ansible.builtin.file:
    path: /flash/squirro/var/lib/squirro/storage
    group: squirro
    mode: "0775"
    owner: sqprovid
    state: directory
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro pdfconversion directory exists in shared drive
  ansible.builtin.file:
    path: /flash/squirro/var/lib/squirro/pdf_conversion
    group: squirro
    mode: "0755"
    owner: sqpdfcon
    state: directory
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro storage localfile exists in shared drive
  ansible.builtin.file:
    path: /flash/squirro/var/lib/squirro/storage/localfile
    group: squirro
    mode: "0775"
    owner: sqprovid
    state: directory
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro storage community_pictures exists in shared drive
  ansible.builtin.file:
    path: /flash/squirro/var/lib/squirro/storage/community_pictures
    group: squirro
    mode: "0775"
    owner: sqtopic
    state: directory
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Ensure squirro storage project_pictures exists in shared drive
  ansible.builtin.file:
    path: /flash/squirro/var/lib/squirro/storage/project_pictures
    group: squirro
    mode: "0775"
    owner: sqtopic
    state: directory
  run_once: true
  when: squirro_clusternode | default(false) | bool

- name: Setup cluster node to use /flash
  when: squirro_clusternode | default(false) | bool
  block:
    - name: Ensure /var/lib/squirro is setup before creating symlink
      ansible.builtin.file:
        path: /var/lib/squirro
        group: squirro
        mode: "0755"
        owner: root
        state: directory
      when: configure_apps_dir is not defined
    - name: Ensure /var/lib/squirro/storage is setup before creating symlink
      ansible.builtin.file:
        path: /var/lib/squirro/storage
        group: squirro
        mode: "0775"
        owner: sqprovid
        state: directory
    - name: Set symlink for /var/lib/squirro/machinelearning
      ansible.builtin.file:
        path: /var/lib/squirro/machinelearning
        src: /flash/squirro/var/lib/squirro/machinelearning
        state: link
    - name: Set symlink for /var/lib/squirro/temp
      ansible.builtin.file:
        path: /var/lib/squirro/temp
        src: /flash/squirro/var/lib/squirro/temp
        state: link
    - name: Set symlink for /var/lib/squirro/storage/community_pictures
      ansible.builtin.file:
        path: /var/lib/squirro/storage/community_pictures
        src: /flash/squirro/var/lib/squirro/storage/community_pictures
        state: link
    - name: Set symlink for /var/lib/squirro/storage/localfile
      ansible.builtin.file:
        path: /var/lib/squirro/storage/localfile
        src: /flash/squirro/var/lib/squirro/storage/localfile
        state: link
    - name: Set symlink for /var/lib/squirro/pdf_conversion
      ansible.builtin.file:
        path: /var/lib/squirro/pdf_conversion
        src: /flash/squirro/var/lib/squirro/pdf_conversion
        state: link
    - name: Set symlink for /var/lib/squirro/storage/project_pictures
      ansible.builtin.file:
        path: /var/lib/squirro/storage/project_pictures
        src: /flash/squirro/var/lib/squirro/storage/project_pictures
        state: link
