7

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
guettli
  • 25,042
  • 81
  • 346
  • 663
  • can you tell how long it takes? – dahrens Mar 10 '16 at 16:03
  • @dahrens sorry, I have no numbers at the moment. But speed is only one concern. The other is: Addressability. I want to be able to update one particular virtualenv without touching the other virtualenvs. – guettli Mar 10 '16 at 16:33

1 Answers1

6

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

dahrens
  • 3,879
  • 1
  • 20
  • 38
  • I guess `salt '*' state.sls venv1` instead of highstate should work. If venv1 and venv2 share a common set of requirements, how to write this (without code duplication)? – guettli Mar 08 '16 at 07:55
  • you might create another state with the requirements and include that state in each venv like [explained in salt docs](https://docs.saltstack.com/en/latest/ref/states/requisites.html#require-an-entire-sls-file) – dahrens Mar 08 '16 at 08:03
  • keep in mind that you want to be able to highstate your minions properly. how long does it actually take to highstate them? – dahrens Mar 08 '16 at 08:09