I'm using ansible for some deployment issues.
I want to do the following:
1. Install virtualenv
2. Activate installed virtual environment
3. Check if I'm in virtual environment
For this purposes I have the following playbook:
---
- hosts: servers
tasks:
- name: update repository
apt: update_cache=yes
sudo: true
tasks:
- name: install git
apt: name=git state=latest
sudo: true
tasks:
- name: install pip
apt: name=python-pip state=latest
sudo: true
tasks:
- name: installing postgres
sudo: true
apt: name=postgresql state=latest
tasks:
- name: installing libpd-dev
sudo: true
apt: name=libpq-dev state=latest
tasks:
- name: installing psycopg
sudo: true
apt: name=python-psycopg2 state=latest
tasks:
- name: configuration of virtual env
sudo: true
pip: name=virtualenvwrapper state=latest
tasks:
- name: create virtualenv
command: virtualenv venv
tasks:
- name: virtualenv activate
shell: . ~/venv/bin/activate
tasks:
- name: "Guard code, so we are more certain we are in a virtualenv"
shell: echo $VIRTUAL_ENV
register: command_result
failed_when: command_result.stdout == ""
The problem is that sometimes some tasks are not executed, but they have to... For instance in my case the task:
tasks:
- name: create virtualenv
command: virtualenv venv
Is not executed.
But if I will comment 2 last tasks:
tasks:
- name: virtualenv activate
shell: . ~/venv/bin/activate
tasks:
- name: "Guard code, so we are more certain we are in a virtualenv"
shell: echo $VIRTUAL_ENV
register: command_result
failed_when: command_result.stdout == ""
The previous one works...
Can't get what I'm doing wrong. Can somebody hint me?