0

Im making an ansible role to install a clean Django CMS instance, when trying to activate my installed Virtual Env I'm getting a permission error, I have read up that sometimes this can be caused when making the env with different permissions to when you try and activate it. I have tried with and without root sudo in both instances.

I am using a Ubuntu/Trusty64 box.

Here is the error im getting from my task:

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

Here is my role file:

---
- 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

Any advice would be greatly appreciated.

Sam Roberts
  • 245
  • 2
  • 13
  • 1
    Possible duplicate of [Ansible creating a virtualenv](http://stackoverflow.com/questions/26402123/ansible-creating-a-virtualenv) – Konstantin Suvorov Mar 14 '17 at 18:45
  • You can't use `activate` this way, because each Ansible task is a different session. – Konstantin Suvorov Mar 14 '17 at 18:46
  • @KonstantinSuvorov Thanks for the response, I have tried running the following task: `- name: Install Django-CMS Insaller command: . env/bin/activate && pip install djangocms-installer become: yes` But it is still saying permission denied. – Sam Roberts Mar 15 '17 at 09:55

1 Answers1

2

You should not do it this way in the first place!

Use pip package with virtualenv parameters. If you still want to activate. See example in this SO question.

If you still want to activate virtual environment inside a shell, you should use shell module (not command!) for source bin/activate to work. source and . are bash built-ins, so command module can't execute them.

Community
  • 1
  • 1
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Thanks for pointing that out, on closer inspection of the pip documentation I should have taken this approach in the first place, it has fixed installing the Python Packages in the venv but I'm still trying to get the djangocms installer to work. – Sam Roberts Mar 15 '17 at 16:41