{"id":20331011,"url":"https://github.com/cans/gitvenv","last_synced_at":"2026-05-08T02:04:13.103Z","repository":{"id":139898068,"uuid":"87568656","full_name":"cans/gitvenv","owner":"cans","description":"Clone Python project git repositories and setup a virtual environment for each","archived":false,"fork":false,"pushed_at":"2017-10-02T13:41:24.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T15:24:21.216Z","etag":null,"topics":["ansible-galaxy","ansible-role","git","python","virtualenv"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-07T17:05:00.000Z","updated_at":"2022-06-01T09:17:52.000Z","dependencies_parsed_at":"2024-06-28T13:46:24.429Z","dependency_job_id":null,"html_url":"https://github.com/cans/gitvenv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fgitvenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fgitvenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fgitvenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cans%2Fgitvenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cans","download_url":"https://codeload.github.com/cans/gitvenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241845929,"owners_count":20029970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible-galaxy","ansible-role","git","python","virtualenv"],"created_at":"2024-11-14T20:18:28.380Z","updated_at":"2025-12-03T02:05:25.824Z","avatar_url":"https://github.com/cans.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"cans.gitvenv\n============\n\nClone Python project git repositories and setup a virtual environment for each\n\n\n## How does it works\n\nThis roles works on a list of repositories. For each repository in the list,\nit will clone it, create a virtualenv for it and install checked-out code\nrequirements inside the virtualenv.\n\nIt will also setup the user shell config so it can use the created virtual\nenvironment with virtualwrapper's `workon` command.\n\nEach repository to clone and setup has to be specified as follows:\n\n      - name: myapp\n        bare: \"yes\"                                 # default: false\n        default: true                               # default: {{omit}}\n        dest: \"/var/lib\"                            # default: {{gitvenv_clone_dir}}\n        requires: \"dev-requirements.txt\"            # default: {{gitvenv_requirements}}\n        site_packages: true                         # default: false\n        url: git@github.com:Account/repository.git  # default: \"{{gitvenv_base_url + '/' + name + '.git'}}\"\n        install: true                               # default: false\n        branch: feature/fancy-new-one               # default: \"{{gitvenv_branch}}\"\n\n\nValues for which no default value is indicated are *mandatory*.\n\nThis will create a clone of the repository found at `{{url}}`\n(`git@github.com/Account/repository.git` here) in `{{dest}}/{{name}}`\n(`/var/lib/myapp` here). Which is roughly equivalent to firing the\ncommand:\n\n    git clone {{url}} {{dest}}/{{name}}\n\nOr when expanded:\n\n    git clone git@github.com:Account/repository.git /var/lib/myapp\n\nThen it will create a virtualenv in `{{workon_home}}` named `{{name}}`,\n(that is `/opt/virtualenv/myapp`). Which boils down to:\n\n    virtualenv /opt/virtualenv/myapp\n    cd /var/lib/myapp\n    pip install --upgrade -r requirements.txt\n\nOn the virtualenv is setup, you may want to install the code you checked\nout from git inside the virtualenv. If you set the `install` variable\nto `true`, then this role will install do so, in development mode:\n\n    cd /var/lib/myapp\n    pip install -e .\n\n\nAnd finally it will update the users `~/.bashrc` to define and export\nthe `WORKON_HOME` variable, set to the value of`gitvenv_workon_home_dir`;\nas well as add a call to the `workon` command with the name of the\nvirtual environment which definition contains the `default` variable\nset to `true`. This will ensure that virtual environment is active upon\nlogin.\n\n\n## Notes\n\nTo be able to set-up the user's shell in a consistent manner, this role\nassumes all virtual environment will be created in the same place and\nfor a unique user. This means you cannot override the `gitvenv_user`\nand `gitvenv_workon_home_dir` on a per-repository basis.\n\nYou can however use this roles several times in a single playbook to\nclone several git repositories and setup their respective virtual\nenvironments and for different users.\n\n\nRequirements\n------------\n\nThis role assumes `git` and `pip` are available on the target host.\n\n\nRole Variables\n--------------\n\nAll the variables of this role are namespaced using the prefix `gitvenv_`\n\n\nRole input variables:\n\n- `gitvenv_base_url`: the base url to use if not url is given. The url\n  to use for the repository to clone is then:\n\n       \"{{ gitvenv_base_url + '/' + name + '.git'}}\"\n\n  Where name is the name given in the repository defition (see above).\n- `gitvenv_clone_dir`: the directory in which store git clones\n- `gitvenv_home_dir`:\n- `gitvenv_git_force`: whether to allow git to override local changes (default: `false`);\n- `gitvenv_python`: the version of python with which create the virtual\n  environment(s);\n- `gitvenv_requirements_file`: the default filename (or path, relative\n  to `{{dest}}/{{name}}`) of the pip requirements file to use.\n- `gitvenv_user`: the user for which install and setup the virtual\n  environment(s) (default: `ansible_user_id`);\n- `gitvenv_workon_home_dir`: the directory in which install the virtual\n  environment(s) (default: `\"{{gitvenv_workon_home_dir}}/{{gitvenv_virtualenvs_dirname}}\"`);\n- `gitvenv_workon_regex`: the pattern used to find the virtualenv activation command in the\n  users shell profile.\n\nAll those variables are defined in the `defaults/main.yml` file. They can\nbe overriden as you need either globally, _e.g._ in you playbook's `vars`\nsection or at the role level (_cf._ [examples](#Example Playbook) below)\n\n\nVariables intended to be used in other roles:\n\n\n- `gitvenv_virtualenvs_dirname`: the name of the directory in which store\n  Python virtual environments. Helper (default: `.virtualenvs`);\n\nAll those variables are defined in the `vars/main.yml` file.\n\n\nDependencies\n------------\n\nThis role has no dependencies\n\n\nExample Playbook\n----------------\n\nHere is an example playbook to clone and setup a virtualenv for a project.\n\n    - hosts: devel\n      vars:\n        gitvenv_clone_dir: \"/home/cans/projects/aurora\"  # All repo. will be cloned here\n        project_aurora_repositories:\n          - name: \"ssh-harness\"\n            url: \"https://github.com/cans/ssh-harness.git\"\n          - name: \"vcs-ssh\"\n            url: \"https://github.com/cans/vcs-ssh.git\"\n          - name: \"vcsd\"\n            url: \"https://github.com/cans/vcsd.git\"\n            dest: \"/home/cans/projects/aurora\"  # Override clone destination directory.\n\n      roles:\n        - role: cans.gitvenv\n          gitvenv_repositories: \"{{project_aurora_repositories}}\"\n          gitvenv_user: \"cans\"\n          gitvenv_workon_home_dir: \"~/.virtualenvs/\"\n          gitvenv_python: python2.7\n\nOf course most variable would be better defined in a seperate file under `vars/` and\nincluded in the playbook.\n\n\nLicense\n-------\n\nGPLv2\n\nAuthor Information\n------------------\n\nCopyright © 2017, Nicolas CANIART\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcans%2Fgitvenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcans%2Fgitvenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcans%2Fgitvenv/lists"}