Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Salt: manage 100+ virtualenvs on one host

How can we structure the salt state tree to be able to run highstate for one virtualenv out of a large number running on a host?

We run virtualenvs for development and in production, using fabric. We want to switch from fabric to salt. Everything works nice, except that highstate takes too long. We have 100+ virtualenvs on one host, and caling highstate would update 100+ virtualenvs.

like image 333
guettli Avatar asked Mar 07 '16 16:03

guettli


1 Answers

salt '*' state.highstate

always applies all states to your minion. It depends on your states why it takes quite a while until highstate returns.

It is possible to organize the deployment by using seperate states for each venv. Individual states can be applied like that:

salt '*' state.sls venv1

A simple salt tree might look like this.

    .
    +-- salt
    |   +-- _prereq.sls
    |   +-- venv1.sls
    |   +-- venv2.sls
    |   +-- top.sls

If you need stuff to be done as prerequisite for each venv in the same way you might use something like that:

_prereq.sls

install_something:
  pkg.installed:
    pkgs: ['foo', 'bar']

venv1.sls

include:
  - _prereq

myvenv_state:
  virtualenv.managed:
    - system_site_packages: False
    - requirements: salt://requirements.txt
    - require:
      - sls: _prereq

I prefer to be able to highstate my minions without thinking about it, so i try to avoid addressable states. But it might fit your needs.

You might also want to have a look at salt.states.virtualenv

like image 60
dahrens Avatar answered Oct 14 '22 08:10

dahrens