git - Ansible:如何初始化 git 裸存储库并将其克隆到同一台机器?

标签 git ansible git-bare

我想问你如何使用 Ansible 实现这种情况。

我的主要目标是 nit git 裸存储库并将其克隆到同一台机器 (/var/www)。 我通常的步骤是:

1) git init —bare (运行在/git/project-name)

2) git clone/git/project-name —no-hardlinks (在/var/www 中运行)

当我愿意使用 Ansible 来做这个案例时,我无法执行第一步——如果是一个空的 git 裸存储库则初始化。

Ansible git 模块要求“repo”参数应填写存储库地址,但如果我只是创建一个,我该如何定义它?

git: repo=?? dest=/git/project-name bare=yes

最佳答案

这是一个示例手册,用于使用新的裸仓库设置 git 服务器:

---
- hosts: git.example.org
  become: true
  tasks:
    - user:
        name: git
        shell: /usr/bin/git-shell
        home: /srv/git

    - authorized_key:
        user: git
        state: present
        key: https://github.com/myuser.keys

    - command: git init --bare /srv/git/myrepo.git
      args:
        creates: /srv/git/myrepo.git/HEAD
      become_user: git

如果您已经在您的服务器上设置了一个 git 用户,那么您只需要关注 command 任务。享受吧!

关于git - Ansible:如何初始化 git 裸存储库并将其克隆到同一台机器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39204455/

相关文章:

裸存储库上的 Git mailmap

linux - 如何将 "attach"工作目录到裸 GIT 存储库

git - 将 svn-remote 添加到现有的 git repo

ansible - 如何在 Ansible 中将一个 yml 文件中的计算变量分配给另一个 yml 文件?

显示 .gitignore 忽略了哪些特定文件的 Git 命令

docker - Ansible: 'item' 未定义

linux - GCE/安塞波 : How to create a filesystem on a new disk of a GCE instance with ansible

git - 推送分支和标签时,出现错误 : cannot spawn git: no such file or directory

linux - 使用 GIT 在本地服务器和实时服务器之间同步网站文件?

git - 如何使用 Git - cherry-pick 将分支 1 上的文件 X 的补丁添加到分支 2 上的文件 X'?