4

I am trying to write a deploy script with salt. It mostly works. I have to run highstate a couple of times for it work all the way. My biggest issue is working through how to execute commands one after another based on specific first one, and them actually finishing/working.

Here is my demo.sls salt state:

{% set web_root = "/var/www/demo/" %}

/var/www/venv/demo:
  virtualenv.managed:
    - system_site_packages: False
    - require:
      - pkg: python-virtualenv

demo:
  git.latest:
    - name: git://localhost/demo.git
    - target: {{ web_root }}

demo_pip:
  cmd.wait:
    - name: 'source /var/www/venv/demo/bin/activate && pip install -r requirements.txt'
    - cwd: {{ web_root }}
    - watch:
      - git: demo

run_migrations:
  cmd.wait:
    - name: 'source /var/www/venv/demo/bin/activate && python manage.py syncdb --noinput'
    - cwd: {{ web_root }}
    - watch:
      - cmd: demo_pip

restart_gunicorn:
  cmd.wait:
    - name: supervisorctl restart gunicorn
    - watch:
      - cmd: run_migrations

I have set it so that demo_pip runs after the git call (which works great), but to be honest demo_pip doesn't actually run. The output from salt is that it ran, but none of the requirements in requirements.txt were installed.

I have tried to put the requirements in the virtualenv.managed section so that runs it, but I have to run 2 highstates at that point. 1) to get the latest from git, seems to run bot exclusivly 2) to install the requirements. For some reason even after putting the virtualenv.managed section after demo it still doesn't register the new requirements file.

Am I using the wrong cmd? Or do I have an order problem?

Buddy Lindsey
  • 259
  • 3
  • 9

1 Answers1

1

I finally figured this out. It looks like it was a file/folder permissions problem. I set a file.managed for all folders in /var/www to be in group www-data. Also made sure everything executed as www-data, and after that things started working like expected.

Buddy Lindsey
  • 259
  • 3
  • 9