---

- name: Make sure galaxy-app dir is owned by the galaxy user
  file: dest={{ galaxy_server_dir }} owner={{ galaxy_user_name }} group={{ galaxy_user_name }} recurse=yes state=directory

- name: Copy Galaxy setup files (static)
  copy: src={{ item.src }} dest={{ item.dest }} backup=yes
  with_items: "{{ cmg_setup_files }}"

- name: Copy Galaxy extra, user-defined files (static)
  copy: src={{ item.src }} dest={{ item.dest }} owner={{ galaxy_user_name }} group={{ galaxy_user_name }}
  with_items: "{{ cmg_extra_files }}"

- name: Create Galaxy Install DB
  command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/create_db.py -c {{ galaxy_config_file }} install chdir={{ galaxy_server_dir }}"

- name: Set Galaxy's PYTHON_EGG_CACHE
  lineinfile: dest={{ galaxy_server_dir }}/run.sh line="export PYTHON_EGG_CACHE={{ galaxyFS_base_dir }}/.python_eggs" insertafter="^#!/bin/sh"

- name: Set Galaxy's PATH
  lineinfile: dest={{ galaxy_server_dir }}/run.sh line="export PATH={{ galaxyFS_base_dir }}/tools/bin:$PATH" insertafter="^#!/bin/sh"


---

- name: Make sure galaxy-app dir is owned by the galaxy user
  file: dest={{ galaxy_server_dir }} owner={{ galaxy_user_name }} group={{ galaxy_user_name }} recurse=yes state=directory

- name: Copy Galaxy setup files (static)
  copy: src={{ item.src }} dest={{ item.dest }} backup=yes
  with_items: "{{ cmg_setup_files }}"

- name: Copy Galaxy extra, user-defined files (static)
  copy: src={{ item.src }} dest={{ item.dest }} owner={{ galaxy_user_name }} group={{ galaxy_user_name }}
  with_items: "{{ cmg_extra_files }}"

- name: Create Galaxy Install DB
  command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/create_db.py -c {{ galaxy_config_file }} install chdir={{ galaxy_server_dir }}"

- name: Set Galaxy's PYTHON_EGG_CACHE
  lineinfile: dest={{ galaxy_server_dir }}/run.sh line="export PYTHON_EGG_CACHE={{ galaxyFS_base_dir }}/.python_eggs" insertafter="^#!/bin/sh"

- name: Set Galaxy's PATH
  lineinfile: dest={{ galaxy_server_dir }}/run.sh line="export PATH={{ galaxyFS_base_dir }}/tools/bin:$PATH" insertafter="^#!/bin/sh"

- name: Set (all but 'db') galaxyFS dirs to be owned by the galaxy user
  shell: chown {{ galaxy_user_name }}:{{ galaxy_user_name }} -R $(ls {{ galaxyFS_base_dir }} | awk '{if($1 != "db"){ print "{{ galaxyFS_base_dir }}/"$1 }}')

Make sure all the dirs under the galaxyFS are owned by galaxy user (except 'db' dir)/
Make sure all the dirs under the galaxyFS are owned by galaxy user (except 'db' dir)/
