Ansible Venv激活权限被拒绝Django CMS

时间:2017-03-14 17:31:44

标签: python django ansible virtualbox django-cms

我在安装一个干净的Django CMS实例时扮演一个ansible角色,当我尝试激活我安装的虚拟环境时,我收到了一个权限错误,我已经读过,有时这可能是因为使用不同的权限创建了env当你尝试激活它。我在两种情况下都尝试过使用和不使用root sudo。

我正在使用Ubuntu/Trusty64框。

以下是我从我的任务中得到的错误:

TASK [dependancies : Activate Venv] ******************************************** fatal: [default]: FAILED! => {"changed": false, "cmd": ". env/bin/activate", "failed": true, "msg": "[Errno 13] Permission denied", "rc": 13}

这是我的角色档案:

---
- name: Update apt-get
  become: yes
  apt:
    update_cache: yes

- name: Install Packages
  apt:
    name: "{{ item }}"
  with_items:
    - nginx
    - python3
    - python-pip
    - nodejs
    - git
    - python-passlib # for htpasswd
    - postgresql
    - libpq-dev # for postgresql
    - python-psycopg2 # for postgresql
    - ansible # to run ansible-pull
  become: yes

- name: Install Python Libraries
  pip:
    name: "{{ item }}"
    executable: pip
  become: yes
  with_items:
    - virtualenv
    - awscli # for backups

- name: Create Venv
  command: virtualenv env
  args:
    creates: env/bin/activate

- name: Activate Venv
  command: . env/bin/activate

- name: Install Django-CMS Insaller
  pip:
    name: djangocms-installer
    executable: pip

- name: Create Folder
  file: path=django state=directory

- name: Create Django CMS
  command: djangocms -s -p . testSite
  args:
    chdir: django
  become: yes

非常感谢任何建议。

1 个答案:

答案 0 :(得分:2)

首先,你不应该这样做!

使用带有pip参数的virtualenv个包。如果你还想激活。请参阅this SO question中的示例。

如果您仍想在shell中激活虚拟环境,则应使用shell模块(而不是command!)来source bin/activate工作。 source.是bash内置函数,因此command模块无法执行它们。

相关问题