在Ansible中添加远程git仓库可以使用git模块中的remote
参数。在已有的仓库下添加远程仓库需要使用git_config
模块中的config
参数。
示例代码如下:
- name: Add upstream remote to repository
git:
repo: /path/to/repo
remote:
name: upstream
url: git@github.com:upstream/repo.git
state: present
- name: Add upstream remote to all repositories in a directory
find:
paths: /path/to/repos
patterns: .git
recurse: yes
register: repos
- name: Configure upstream remote for all repositories
git_config:
file: "{{ item.path }}/config"
key: "remote.upstream.url"
value: "git@github.com:upstream/repo.git"
state: present
loop: "{{ repos.files }}"