Setting up a python virtual environment with Salt's virtualenv.managed or pip.installed?

StackOverflow https://stackoverflow.com/questions/22870751

  •  28-06-2023
  •  | 
  •  

문제

I'm trying to use either a pip.installed or a virtualenv.managed state to set up a virtualenv using a requirements file that lives on the minion (installed by an earlier git.latest state). Here's the version using pip.installed:

mysite-env:
  virtualenv.managed:
    - name: /opt/django/mysite
    - cwd: /opt/django/mysite
    - user: mysite
    - runas: mysite
    - system_site_packages: True

mysite-reqs:
  pip.installed:
    - no_index: True
    - find_links: http://pypi.mysite.com/
    - requirements: /opt/django/mysite/requirements/production.txt
    - pip_exists_action: switch
    - cwd: /opt/django/mysite
    - pip_bin: /opt/django/mysite/bin/pip
    - bin_env: /opt/django/mysite
    - user: mysite
    - watch:
      - git: mysite-project

When I try and run this state, I get this error:

          ID: mysite-reqs
    Function: pip.installed
      Result: False
     Comment: Unable to process requirements file /opt/django/mysite/requirements/production.txt. Error: Ignoring indexes: https://pypi.python.org/simple/
              Could not open requirements file: [Errno 2] No such file or directory: '/tmp/requirements.txt'
              Storing debug log for failure in /home/mysite/.pip/pip.log

But that's not the path I'm passing to requirements. This looks kind of like a bug, like maybe /tmp/requirements.txt is hard-coded, because it expects me to use a salt:// URL instead of a local file path.

Am I doing something wrong? Is this a bug, and is there a good way to work around it?

도움이 되었습니까?

해결책

It's my first day using Saltstack and Python and I was googling for environment configuration help and came across your question in my search results.

The next search result I clicked contains the same error as yours and suggests that this is caused by SaltStack moving the environment to /tmp for chowning.

The solution was to add the following to your salt state:

no_chown: True

Hope it helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top