Skip to content

Instantly share code, notes, and snippets.

@oc
Created October 10, 2012 14:28
Show Gist options
  • Save oc/3865980 to your computer and use it in GitHub Desktop.
Save oc/3865980 to your computer and use it in GitHub Desktop.
template - default variables prob...
## /etc/unicorn/blahblah.conf
RACK_ROOT="/srv/www/blahblah.muda.no"
IS_RAILS="True"
UNICORN_BIN="bundle exec bin/unicorn_rails"
UNICORN_PORT="None" # <=========== WRONG!! WTF?!
# Export RACK_ENV.
export RACK_ENV="custom"
# Map other environment variables to set in launcher
export SHITFOO="custom"
export LOGIN="foo"
## /etc/unicorn/staging.conf
RACK_ROOT="/srv/www/staging.muda.no"
IS_RAILS="True"
UNICORN_BIN="bundle exec bin/unicorn" # <=========== default value works here...
UNICORN_PORT="3000"
# Export RACK_ENV.
export RACK_ENV="production"
# Map other environment variables to set in launcher
# salt state init - only the relevant parts...
{% for svc in pillar['unicorn_services'] %}
/etc/unicorn/{{ svc.name }}.conf:
file.managed:
- source: salt://unicorn/etc/unicorn/unicorn.conf.jinja
- template: jinja
- user: www-data
- group: www-data
- context:
name: {{ svc.name }}
root: {{ svc.root }}
unicorn_bin: {{ svc.unicorn_bin or "bundle exec bin/unicorn" }}
unicorn_port: {{ svc.unicorn_port or "" }} # <======================= PROBLEM, returns "None"
rack_env: {{ svc.rack_env or "production"}}
rails: {{ svc.rails or "" }}
environment: {{ svc.environment or {} }}
- require:
- file: /etc/unicorn
{% endfor %}
RACK_ROOT="{{ root }}"
IS_RAILS="{{ rails }}"
UNICORN_BIN="{{ unicorn_bin }}"
UNICORN_PORT="{{ unicorn_port }}"
# Export RACK_ENV.
export RACK_ENV="{{ rack_env }}"
# Map other environment variables to set in launcher
{% for k, v in environment.items() %}
export {{ k }}="{{ v }}"
{%- endfor %}
## Pillar data
unicorn_services:
# first element should have no unicorn_port (should default to empty string)
- name: blahblah
root: /srv/www/blahblah.muda.no
unicorn_bin: bundle exec bin/unicorn_rails
rack_env: custom
rails: True
environment:
SHITFOO: custom
LOGIN: foo
# second element should has a unicorn_port (is correctly set)
- name: staging
root: /srv/www/staging.muda.no
unicorn_port: 3000
rack_env: production
rails: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment