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