running mkvirtualenv using ansible

前端 未结 3 1266
悲哀的现实
悲哀的现实 2021-01-08 01:13

I am provisioning a machine using ansible. I managed to install virtualenv and virtualenvwrapper fine on the vm. However, I can\'t seem to create a virtualenv on the vm.

相关标签:
3条回答
  • 2021-01-08 01:30

    You can create an environment using mkvirtualenv like this. I was hoping to be able to use the toggleglobalsitepackages, but I found that toggling is not so convenient in an automated session.

    - name: Make a virtualenv
      shell: . /usr/share/virtualenvwrapper/virtualenvwrapper.sh && mkvirtualenv {{ venv }}
      args:
        executable: /bin/bash
        creates: "{{ venvabs }}"
    
    0 讨论(0)
  • 2021-01-08 01:36

    Additionally to @SiggyF's excellent answer, I would like to add: In case that it appears that this ansible task fails, as it happens somehow with me, you can use the failed_when feature (ansible 1.4+):

    - name: Make virtualenv
      shell: "./usr/share/virtualenvwrapper/virtualenvwrapper.sh && mkvirtualenv {{ project }} --python={{ python }} --no-site-packages"
      args:
        executable: /bin/bash
        creates: "{{ virtualenv_dir }}/{{ project }}"
      register: mkvirtualenv
      failed_when: 'mkvirtualenv.changed and "New python executable" not in mkvirtualenv.stdout'
    
    0 讨论(0)
  • 2021-01-08 01:44

    Source only adds virtualenvwrappers to the shell its invoked in, which you then exit immediately. In any case, I would not use virtualenvwrapper for this. Invoke virtualenv directly.

    0 讨论(0)
提交回复
热议问题