Skip to content

Instantly share code, notes, and snippets.

@natefoo
Created August 20, 2014 20:39
Show Gist options
  • Save natefoo/28c2ebddd0e75d11ffa5 to your computer and use it in GitHub Desktop.
Save natefoo/28c2ebddd0e75d11ffa5 to your computer and use it in GitHub Desktop.
Automagic Galaxy Config generation
---
- hosts: localhost
connection: local
vars:
galaxy_config:
"server:web0":
host: 0.0.0.0
port: 8080
"server:web1":
host: 0.0.0.0
port: 8081
"app:main":
"database_connection": "postgresql:///galaxy"
tasks:
- name: Generate INI
template: src=universe_wsgi.ini.j2 dest=universe_wsgi.ini
#- define galaxy_config if it doesn't exist, for later ease of use -#}
{%- if galaxy_config is not defined or galaxy_config == None -%}
{%- set galaxy_config = {} %}
{% endif %}
{% for server in galaxy_config if server.startswith('server:') %}
{#- server: must contain use, set it if unset -#}
{#- default to enabling the threadpool, but this can be overridden -#}
[{{ server }}]
{{ "use = egg:Paste#http" if galaxy_config[server]['use'] is not defined else "" }}
{{ "use_threadpool = True" if galaxy_config[server]['use_threadpool'] is not defined else "" }}
{% for opt in galaxy_config[server] %}
{{ opt }} = {{ galaxy_config[server][opt] }}
{% endfor %}
{% else %}
[server:main]
use = egg:Paste#http
use_threadpool = True
{% endfor %}
{#- add any other defined sections (e.g. [uwsgi]). -#}
{% for section in galaxy_config if not section.startswith('server:') and not section == 'app:main' %}
[{{ section }}]
{% for opt in galaxy_config[section] %}
{{ opt }} = {{ galaxy_config[section][opt] }}
{% endfor %}
{% endfor %}
{#- app:main must exist and must contain paste.app_factory, but everything else is optional. -#}
[app:main]
{% if 'app:main' in galaxy_config %}
{{ "paste.app_factory = galaxy.web.buildapp:app_factory" if galaxy_config['app:main']['paste.app_factory'] is not defined else "" }}
{% for opt in galaxy_config['app:main'] %}
{{ opt }} = {{ galaxy_config['app:main'][opt] }}
{% endfor %}
{% else %}
paste.app_factory = galaxy.web.buildapp:app_factory
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment