|
| 1 | +This role clones a set of git repositories, handling multiple remotes and managing different branches for each remote. It also provides basic support for bundle installs for Ruby projects, and pip installs within a virtual environment for Python projects. The role aims to present a single, simple interface in Ansible variables for managing a collection of locally cloned git repositories. |
| 2 | + |
| 3 | +Role Variables |
| 4 | +-------------- |
| 5 | + |
| 6 | +The main data structure for the role is the list of `git_repositories`. Each repository in the list requires the following attributes: |
| 7 | + |
| 8 | +- `name`: The local name of the repository. |
| 9 | +- `dir`: The parent directory to clone the repository from. |
| 10 | +- `remotes`: List of repository remotes, each with `name`, `url`, and `branches`. |
| 11 | + |
| 12 | +Repositories may also have the following optional attributes: |
| 13 | + |
| 14 | +- `install_gems`: Boolean to indicate if Ruby gems should be installed. This assumes the cloned repository provides a Gemfile. |
| 15 | +- `python_packages`: A list of python packages to install in a venv within the repository. |
| 16 | + |
| 17 | +Each remote requires the following attributes: |
| 18 | + |
| 19 | +- `name`: Name of the remote. |
| 20 | +- `url`: URL of the remote. |
| 21 | +- `branches`: A list of branches in the remote repository that will be created in the local clone. |
| 22 | + |
| 23 | +Examples |
| 24 | +-------- |
| 25 | + |
| 26 | +Basic example of the `git_repositories` variable, configuring two repositories, each with a single remote and a single branch: |
| 27 | + |
| 28 | +```yaml |
| 29 | +git_repositories: |
| 30 | + - name: 'foreman' |
| 31 | + dir: '/home/vagrant' |
| 32 | + remotes: |
| 33 | + - name: 'origin' |
| 34 | + url: 'git@github.com/my_github_user/foreman.git' |
| 35 | + branches: |
| 36 | + - 'develop' |
| 37 | + - name: 'katello' |
| 38 | + dir: '/home/vagrant' |
| 39 | + remotes: |
| 40 | + - name: 'origin' |
| 41 | + url: 'git@github.com/my_github_user/katello.git' |
| 42 | + branches: |
| 43 | + - 'master' |
| 44 | +``` |
| 45 | +
|
| 46 | +Example configuring a repository with multiple remotes and branches and installing gems from the project's Gemfile. The checkout will be of the first branch on the first remote when performing the bundle install: |
| 47 | +
|
| 48 | +```yaml |
| 49 | +git_repositories: |
| 50 | + - name: 'foreman' |
| 51 | + dir: '/home/vagrant' |
| 52 | + remotes: |
| 53 | + - name: 'upstream' |
| 54 | + url: 'git@github.com/theforeman/foreman.git' |
| 55 | + branches: |
| 56 | + - 'develop' |
| 57 | + - name: 'myfork' |
| 58 | + url: 'git@github.com/my_github_user/foreman.git' |
| 59 | + branches: |
| 60 | + - 'exciting-new-feature' |
| 61 | + - 'fix-annoying-bug' |
| 62 | + install_gems: true |
| 63 | +``` |
| 64 | +
|
| 65 | +Installing Python Packages in a Virtual Environment: |
| 66 | +
|
| 67 | +```yaml |
| 68 | +git_repositories: |
| 69 | + - name: 'rpm-packaging' |
| 70 | + dir: '/home/vagrant' |
| 71 | + remotes: |
| 72 | + - name: 'downstream' |
| 73 | + url: 'git@gitlab.example.com/systems_management/rpm-packaging.git' |
| 74 | + branches: |
| 75 | + - 'STREAM' |
| 76 | + - 'VERSION-1' |
| 77 | + - 'VERSION-2' |
| 78 | + - 'VERSION-3' |
| 79 | + python_packages: |
| 80 | + - 'ansible' |
| 81 | + - 'obal' |
| 82 | + - 'tito' |
| 83 | +``` |
0 commit comments