Skip to content

Commit

Permalink
Remove a lot of cruft, switch to yaml-style task params, and update for
Browse files Browse the repository at this point in the history
Ansible 2.2 compatibility
  • Loading branch information
natefoo committed Apr 6, 2017
1 parent 19535b5 commit c9f923a
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 282 deletions.
339 changes: 162 additions & 177 deletions README.md

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Controls which tasks are included, in case you need to perform different
# options on different hosts or server directories.
galaxy_manage_clone: yes
galaxy_vcs: hg
galaxy_force_checkout: no
# Download the Galaxy instead cloning, for throw away boxes (e.g. Docker)
galaxy_manage_download: no
Expand All @@ -13,22 +12,16 @@ galaxy_manage_mutable_setup: yes
galaxy_manage_database: yes
galaxy_fetch_dependencies: yes

# Set a version of pip to install
galaxy_pip_version: 8.1.2

# legacy
galaxy_fetch_eggs: yes

# Where to clone Galaxy from
galaxy_repo: https://bitbucket.org/galaxy/galaxy-dist
galaxy_git_repo: https://github.com/galaxyproject/galaxy.git
# Where to clone Galaxy from. Backwards compatibility with galaxy_git_repo
galaxy_repo: "{{ galaxy_git_repo | default('https://github.com/galaxyproject/galaxy.git') }}"

# This can be a tag (as shown here) but doing so will cause the revision check
# task to always report "changed"
galaxy_changeset_id: stable
# task to always report "changed". Backwards compatibility with
# galaxy_changeset_id.
galaxy_commit_id: "{{ galaxy_changeset_id | default('master') }}"

# Download URL (if used)
galaxy_download_url: "{{ galaxy_repo }}/get/{{ galaxy_changeset_id }}.tar.gz"
galaxy_download_url: "{{ galaxy_repo }}/get/{{ galaxy_commit_id }}.tar.gz"

# This will automatically be used by run.sh
galaxy_venv_dir: "{{ galaxy_server_dir }}/.venv"
Expand Down
6 changes: 3 additions & 3 deletions files/makepyc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python

import sys
import compileall
import sys

from os import walk, unlink
from os.path import join, splitext, exists
from os import unlink, walk
from os.path import exists, join, splitext


assert sys.argv[1], "usage: makepyc /path/to/lib"
Expand Down
13 changes: 8 additions & 5 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

# TODO: Magical restarters depending on how you're running Galaxy.
- name: restart galaxy
debug: msg="RESTARTER NOT IMPLEMENTED - Please restart Galaxy manually"
debug:
msg: "RESTARTER NOT IMPLEMENTED - Please restart Galaxy manually"

- name: email administrator with changeset id
mail: from="{{ galaxy_admin_email_from | default( 'root' ) }}" to="{{ galaxy_admin_email_to }}"
subject="Galaxy instance {{ galaxy_instance_hostname | default( inventory_hostname ) }} is at changeset {{ galaxy_changeset_id }}"
body=" "
- name: email administrator with commit id
mail:
from: "{{ galaxy_admin_email_from | default( 'root' ) }}"
to: "{{ galaxy_admin_email_to }}"
subject: "Galaxy instance {{ galaxy_instance_hostname | default( inventory_hostname ) }} is at commit {{ galaxy_commit_id }}"
body: " "
when: galaxy_admin_email_to is defined
55 changes: 25 additions & 30 deletions tasks/clone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@
# Manage Galaxy clone

- name: Check for Galaxy
stat: path={{ galaxy_server_dir }}/lib/galaxy
register: lib_galaxy

- name: Get current Galaxy changeset (hg)
command: "{{ hg_executable | default('hg') }} parents --template '{node}' chdir={{ galaxy_server_dir }}"
register: current_changeset_id
changed_when: False
when: lib_galaxy.stat.exists and galaxy_vcs == 'hg'

- name: Get current Galaxy commit id (git)
command: "{{ git_executable | default('git') }} rev-parse HEAD chdir={{ galaxy_server_dir }}"
register: current_changeset_id
changed_when: False
when: lib_galaxy.stat.exists and galaxy_vcs == 'git'

- name: Report current Galaxy changeset
debug: msg="Current changeset of {{ galaxy_server_dir }} {{ current_changeset_id.stdout | default(-1) }} does not match playbook version {{ galaxy_changeset_id }}" #"
stat:
path: "{{ galaxy_server_dir }}/lib/galaxy"
register: galaxy_stat_out

- name: Get current Galaxy commit id
command: "{{ git_executable | default('git') }} rev-parse HEAD"
args:
chdir: "{{ galaxy_server_dir }}"
register: current_commit_id
changed_when: no
when: galaxy_stat_out.stat.exists

- name: Report current Galaxy commit id
debug:
msg: "Current version of {{ galaxy_server_dir }} {{ current_commit_id.stdout | default(-1) }} does not match playbook version {{ galaxy_commit_id }}"
changed_when: True
when: lib_galaxy.stat.exists and (current_changeset_id.stdout | default(-1) != galaxy_changeset_id)

- name: Update Galaxy to correct changeset (hg)
hg: dest={{ galaxy_server_dir }} force={{ galaxy_force_checkout }} purge=no repo={{ galaxy_repo }} revision={{ galaxy_changeset_id }} executable={{ hg_executable | default(omit) }}
when: galaxy_vcs == 'hg'
notify:
- restart galaxy
- email administrator with changeset id

- name: Update Galaxy to correct changeset (git)
git: dest={{ galaxy_server_dir }} force={{ galaxy_force_checkout }} repo={{ galaxy_git_repo }} version={{ galaxy_changeset_id }} executable={{ git_executable | default(omit) }}
when: galaxy_vcs == 'git'
when: galaxy_stat_out.stat.exists and (current_commit_id.stdout | default(-1) != galaxy_commit_id)

- name: Update Galaxy to correct ref (git)
git:
dest: "{{ galaxy_server_dir }}"
force: "{{ galaxy_force_checkout }}"
repo: "{{ galaxy_repo }}"
version: "{{ galaxy_commit_id }}"
executable: "{{ git_executable | default(omit) }}"
notify:
- restart galaxy
- email administrator with changeset id
- email administrator with commit id

- include: virtualenv.yml

Expand Down
28 changes: 14 additions & 14 deletions tasks/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
# Manage Galaxy Database

- name: Get current Galaxy DB version
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} db_version chdir={{ galaxy_server_dir }}"
environment:
GALAXY_EGGS_PATH: "{{ galaxy_eggs_path | default(galaxy_server_dir ~ '/eggs') }}"
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} db_version"
args:
chdir: "{{ galaxy_server_dir }}"
register: current_db_version
changed_when: False
changed_when: no
failed_when: current_db_version.rc != 0 and 'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr

- name: Get maximum Galaxy DB version
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} version chdir={{ galaxy_server_dir }}"
environment:
GALAXY_EGGS_PATH: "{{ galaxy_eggs_path | default(galaxy_server_dir ~ '/eggs') }}"
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} version"
args:
chdir: "{{ galaxy_server_dir }}"
register: max_db_version
changed_when: False
changed_when: no

- name: Create Galaxy DB
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/create_db.py -c {{ galaxy_config_file }} chdir={{ galaxy_server_dir }}"
environment:
GALAXY_EGGS_PATH: "{{ galaxy_eggs_path | default(galaxy_server_dir ~ '/eggs') }}"
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/create_db.py -c {{ galaxy_config_file }}"
args:
chdir: "{{ galaxy_server_dir }}"
when: "'migrate.exceptions.DatabaseNotControlledError' in current_db_version.stderr"

- name: Upgrade Galaxy DB
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} upgrade chdir={{ galaxy_server_dir }}"
environment:
GALAXY_EGGS_PATH: "{{ galaxy_eggs_path | default(galaxy_server_dir ~ '/eggs') }}"
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} upgrade"
args:
chdir: "{{ galaxy_server_dir }}"
when: current_db_version.stdout != max_db_version.stdout and 'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr
33 changes: 3 additions & 30 deletions tasks/dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
---
# Manage Galaxy Eggs
# Manage Galaxy framework dependencies

- name: Check if Galaxy uses eggs or wheels
stat:
path: "{{ galaxy_requirements_file }}"
register: requirements_txt

- name: Fetch Galaxy eggs
command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/fetch_eggs.py -c {{ galaxy_config_file }} chdir={{ galaxy_server_dir }}"
environment:
GALAXY_EGGS_PATH: "{{ galaxy_eggs_path | default(galaxy_server_dir ~ '/eggs') }}"
PYTHONPATH: null
when: not requirements_txt.stat.exists
register: fetch_eggs_result
changed_when: (fetch_eggs_result.rc == 0) and (fetch_eggs_result.stdout != "")

# virtualenv_command is still required if `virtualenv` isn't on $PATH, even if
# the venv already exists.
- name: Install Galaxy pip
pip:
name: pip
version: "{{ galaxy_pip_version }}"
virtualenv: "{{ galaxy_venv_dir }}"
virtualenv_command: "{{ pip_virtualenv_command | default( 'virtualenv' ) }}"
environment:
PYTHONPATH: null
VIRTUAL_ENV: "{{ galaxy_venv_dir }}"
when: requirements_txt.stat.exists
- include: virtualenv.yml

# virtualenv_command is still required if `virtualenv` isn't on $PATH, even if the venv already exists.
- name: Install Galaxy base dependencies
pip:
requirements: "{{ galaxy_requirements_file }}"
Expand All @@ -37,13 +13,11 @@
environment:
PYTHONPATH: null
VIRTUAL_ENV: "{{ galaxy_venv_dir }}"
when: requirements_txt.stat.exists

- name: Collect Galaxy conditional dependency requirement strings
command: "{{ galaxy_venv_dir }}/bin/python -c \"import galaxy.dependencies; print '\\n'.join(galaxy.dependencies.optional('{{ galaxy_config_file }}'))\""
environment:
PYTHONPATH: "{{ galaxy_server_dir }}/lib"
when: requirements_txt.stat.exists
register: conditional_dependencies

- name: Install Galaxy conditional dependencies
Expand All @@ -56,4 +30,3 @@
environment:
PYTHONPATH: null
VIRTUAL_ENV: "{{ galaxy_venv_dir }}"
when: requirements_txt.stat.exists
5 changes: 3 additions & 2 deletions tasks/download.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
- name: Check for Galaxy download receipt
stat: path={{ galaxy_server_dir }}/{{ galaxy_changeset_id }}_receipt
stat:
path: "{{ galaxy_server_dir }}/{{ galaxy_commit_id }}_receipt"
register: download_receipt

- name: Replace current version of Galaxy
shell: "rm -rf '{{ galaxy_server_dir }}' && mkdir '{{ galaxy_server_dir }}' && wget -q -O - {{ galaxy_download_url }} | tar xzf - --strip-components=1 -C {{ galaxy_server_dir }} && touch '{{ galaxy_server_dir }}/{{ galaxy_changeset_id }}_receipt'"
shell: "rm -rf '{{ galaxy_server_dir }}' && mkdir '{{ galaxy_server_dir }}' && wget -q -O - {{ galaxy_download_url }} | tar xzf - --strip-components=1 -C {{ galaxy_server_dir }} && touch '{{ galaxy_server_dir }}/{{ galaxy_commit_id }}_receipt'"
when: not download_receipt.stat.exists

- include: virtualenv.yml
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- galaxy_config_files

- include: dependencies.yml
when: galaxy_fetch_dependencies and galaxy_fetch_eggs
when: galaxy_fetch_dependencies

- include: mutable_setup.yml
when: galaxy_manage_mutable_setup
Expand Down
8 changes: 6 additions & 2 deletions tasks/mutable_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
# Instantiate mutable config files

- name: Create mutable configuration file directories
file: state=directory path={{ item }}
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ galaxy_mutable_config_dir }}"
- "{{ galaxy_tool_dependency_dir }}"

- name: Instantiate mutable configuration files
command: cp {{ item.src }} {{ item.dest }} creates={{ item.dest }}
command: cp {{ item.src }} {{ item.dest }}
args:
creates: "{{ item.dest }}"
with_items: "{{ galaxy_mutable_configs }}"
19 changes: 15 additions & 4 deletions tasks/static_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@
# Manage static Galaxy configuration files

- name: Create Galaxy config dirs
file: state=directory path={{ item }}
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ galaxy_config_dir }}"
- "{{ galaxy_shed_tools_dir }}"

- name: Install additional Galaxy config files (static)
copy: src={{ item.src }} dest={{ item.dest }} backup=yes
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
backup: yes
with_items: "{{ galaxy_config_files }}"

- name: Install additional Galaxy config files (template)
template: src={{ item.src }} dest={{ item.dest }} backup=yes
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
backup: yes
with_items: "{{ galaxy_config_templates }}"

- name: Create Galaxy configuration file
template: src=galaxy.ini.j2 dest={{ galaxy_config_file }} backup=yes
template:
src: "galaxy.ini.j2"
dest: "{{ galaxy_config_file }}"
backup: yes
notify:
- restart galaxy
22 changes: 21 additions & 1 deletion tasks/virtualenv.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
---

# Having pip installed on $PYTHONPATH can break upgrading it, so we install
# once with $PYTHONPATH set (in case it's needed for virtualenv) and then once
# the venv is created we upgrade pip with $PYTHONPATH unset

- name: Create Galaxy virtualenv
pip: name=pip virtualenv={{ galaxy_venv_dir }} virtualenv_command="{{ pip_virtualenv_command | default( 'virtualenv' ) }}"
pip:
name: pip
virtualenv: "{{ galaxy_venv_dir }}"
virtualenv_command: "{{ pip_virtualenv_command | default('virtualenv') }}"
environment:
VIRTUAL_ENV: "{{ galaxy_venv_dir }}"

- name: Ensure pip is the latest release
pip:
name: pip
state: latest
virtualenv: "{{ galaxy_venv_dir }}"
virtualenv_command: "{{ pip_virtualenv_command | default('virtualenv') }}"
environment:
PYTHONPATH: null
VIRTUAL_ENV: "{{ galaxy_venv_dir }}"

0 comments on commit c9f923a

Please sign in to comment.