我正在使用 ansible 解决一些部署问题。
我想做以下事情:
- 安装虚拟环境
- 激活已安装的虚拟环境
- 检查我是否在虚拟环境中
为此,我有以下剧本:
---
- 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 == ""
问题是有时某些任务没有执行,但他们必须......例如在我的情况下任务:
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 == ""
上一个有效...
无法理解我做错了什么。有人可以提示我吗?