# deployment tasks that populate a python virtualenv

**URL:** <https://forum.ansible.com/t/deployment-tasks-that-populate-a-python-virtualenv/13661>\
**Category:** Ansible Project\
**Created:** [October 11, 2013, 2:16am UTC](https://forum.ansible.com/t/deployment-tasks-that-populate-a-python-virtualenv/13661 "2013-10-11T02:16:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 11, 2013, 2:16am UTC](https://forum.ansible.com/t/deployment-tasks-that-populate-a-python-virtualenv/13661/1 "2013-10-11T02:16:57Z")

</div>

This is a common pattern for our deployment tasks:

- checkout a git repo
- pip install one or more requirements.txt files that exist in that repo to populate a virtualenv

Obviously we want to pip install when there is a new commit.

For the cases when the repo commit changes but the requirements.txt files do not change I would prefer not incur the cost of pip installing it. pip won’t make changes but it is still rather expensive to run through all of the requirements.

Here is one way to avoid the overhead:

- git: (check out the repo)

- shell: md5sum path/to/requirements.txt  
register: req\_md5

- stat: path=/var/tmp/requirements.txt.{{ req\_md5.stdout }}  
register: req\_stat

- pip: requirements=path/to/requirements.txt virtualenv=/venv state=present  
when: not req\_stat.stat.exists

- file: path=/var/tmp/requirements.txt.{{ req\_md5.stdout }} state=touch

At the very least I was thinking of creating an md5sum module to replace the first task since I hate having tasks report “changed” for read operations. Can anyone think of a better way to do this?

-John

---

<div class="post-metadata">

**Author:** ![GW1](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@GW1](https://forum.ansible.com/u/GW1)\
**Post date:** [October 11, 2013, 7:36am UTC](https://forum.ansible.com/t/deployment-tasks-that-populate-a-python-virtualenv/13661/2 "2013-10-11T07:36:11Z")

</div>

Hi,

First time do a git clone and install a git hook post-checkout that does pip install and all other migrations. Next time just fetch and checkout new changes and the hook will get automatically triggered.

Greetings,  
gw

---

<div class="post-metadata">

**Author:** ![Robert\_Parrott](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@Robert\_Parrott](https://forum.ansible.com/u/Robert_Parrott)\
**Post date:** [October 11, 2013, 12:30pm UTC](https://forum.ansible.com/t/deployment-tasks-that-populate-a-python-virtualenv/13661/3 "2013-10-11T12:30:17Z")

</div>

T

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [October 11, 2013, 1:39pm UTC](https://forum.ansible.com/t/deployment-tasks-that-populate-a-python-virtualenv/13661/4 "2013-10-11T13:39:31Z")

</div>

The point here though is that I only want to re-populate the virtualenv if the requirements.txt file changes (not every time the repo changes). Is this possible with a git hook?
