saltstack-formulas / uwsgi-formula

Salt formula to manage uwsgi
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Apache License 2.0
9 stars 37 forks source link

Impossible to create "if" rules #8

Closed morsik closed 8 years ago

morsik commented 8 years ago

uWSGI offers to do if directives inside configuration files. They are parse one-by-line, but I don't see it's possible to do with this formula right now.

Example (from http://uwsgi-docs.readthedocs.org/en/latest/tutorials/ReliableFuse.html):

if-not-reload =
  exec-as-user = fuse-zip -r /var/www/app001.zip /app
endif =

Writing in pillar below code will result in rehashed/sorted keys inside, and will break that if:

uwsgi:
  emperor:
    config:
      autoload: 'true'
      master: 'true'
      vacuum: 'true'
      workers: 2
      log-date: 'true'

      emperor: /etc/uwsgi.d

      memory-report: 1
      thunder-lock: 1
      socker: 0.0.0.0:0
      emperor-stats: /tmp/emperor-stats.sock
      emperor-nofollow: 1
      emperor-procname: uwsgi emperor
      procname-master: uwsgi emperor master

      if-not-reload: ''
      exec-as-user: 'fuse-zip -r /var/www/app001.zip /app'
      endif: ''

Output in /etc/uwsgi.ini:

[uwsgi]

autoload = true
emperor = /etc/uwsgi.d
emperor-nofollow = 1
emperor-procname = uwsgi emperor
emperor-stats = /tmp/emperor-stats.sock
endif = 
exec-as-user = fuse-zip -r /var/www/app001.zip /app
gid = uwsgi
if-not-reload = 
log-date = true
master = true
memory-report = 1
no-orphans = true
procname-master = uwsgi emperor master
socker = 0.0.0.0:0
thunder-lock = 1
uid = uwsgi
vacuum = true
workers = 2

This is really wrong. endif before if. exec-as-user broken.

aboe76 commented 8 years ago

this is because, the yaml parsing isn't ordered,, we need some saltstack yaml guru to look at this, I don't have the interal saltstack knowledge to solve this...

morsik commented 8 years ago

@aboe76: I saw that people sometimes use list in formulas instead of dict when order is important. For example:

uwsgi:
  emperor:
    config:
      - autoload: 'true'
      - master: 'true'
      - vacuum: 'true'
      - workers: 2
      - log-date: 'true'

      - emperor: /etc/uwsgi.d

      - memory-report: 1
      - thunder-lock: 1
      - socker: 0.0.0.0:0
      - emperor-stats: /tmp/emperor-stats.sock
      - emperor-nofollow: 1
      - emperor-procname: uwsgi emperor
      - procname-master: uwsgi emperor master

      - if-not-reload: ''
      - exec-as-user: 'fuse-zip -r /var/www/app001.zip /app'
      - endif: ''

Of course you need to be backward compatible with dict (to prevent destroying old configs).

Another approach (above mixed with current dict):

uwsgi:
  emperor:
    config:
      # this doesn't need to be in any order
      - autoload: 'true'
        master: 'true'
        vacuum: 'true'
        workers: 2
        log-date: 'true'

      # then put emperor entry
      - emperor: /etc/uwsgi.d

      # some emperor things
      - memory-report: 1
        thunder-lock: 1
        socket: 0.0.0.0:0
        emperor-stats: /tmp/emperor-stats.sock
        emperor-nofollow: 1
        emperor-procname: uwsgi emperor
        procname-master: uwsgi emperor master

      # this must be in order!
      - if-not-reload: ''
      - exec-as-user: 'fuse-zip -r /var/www/app001.zip /app'
      - endif: ''

Would result in such config (written by hand). Sections inside would be sorted alphabetically, but outside, they could be rendered in list order.

[uwsgi]

autoload = true
log-date = true
master = true
no-orphans = true
vacuum = true
workers = 2

emperor = /etc/uwsgi.d

emperor-nofollow = 1
emperor-procname = uwsgi emperor
emperor-stats = /tmp/emperor-stats.sock
socket = 0.0.0.0:0
memory-report = 1
procname-master = uwsgi emperor master
thunder-lock = 1

if-not-reload = 
exec-as-user = fuse-zip -r /var/www/app001.zip /app
endif = 
lgunsch commented 8 years ago

My pull request #12 and #13 should fix this issue, as it is now possible to use a list of dict to preserve ordering in the configuration.

aboe76 commented 8 years ago

@morsik can you close this issue?

morsik commented 8 years ago

@lgunsch: thanks!