Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git克隆--带Ansible 2.4的镜像_Git_Ansible - Fatal编程技术网

git克隆--带Ansible 2.4的镜像

git克隆--带Ansible 2.4的镜像,git,ansible,Git,Ansible,如何通过ansible 2.4中的git模块实现这一点? 我已经看过文档了,没有mirror克隆的选项 有没有其他方法可以不用直接运行shell命令来实现这一点。。 目前我有一个类似的东西 - name: Clone git repo git: repo: ssh://git@github.com/foo/bar.git key_file: /home/deploy/.ssh/id_rsa dest: /path/to/repo accept_hostkey:

如何通过ansible 2.4中的git模块实现这一点? 我已经看过文档了,没有
mirror
克隆的选项

有没有其他方法可以不用直接运行shell命令来实现这一点。。 目前我有一个类似的东西

- name: Clone git repo
  git:
    repo: ssh://git@github.com/foo/bar.git
    key_file: /home/deploy/.ssh/id_rsa
    dest: /path/to/repo
    accept_hostkey: true
    update: yes
    version: master
    bare: no
  become_user: deploy
  when: repo_created.changed
我喜欢漂亮的配置开关来接受主机密钥等。 我认为另一种选择是这样的。。(尚未测试)


这是我唯一/最好的选择吗?

到目前为止,这是我使用Ansible 2.4克隆镜像回购最必要的方法

- name: Add githubs key to known hosts
  known_hosts:
    path: /home/deploy/.ssh/known_hosts
    name: github.com
    key: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
    state: present
  sudo_user: deploy

- name: change the owner of the known_hosts file to deploy user
# because https://github.com/ansible/ansible/issues/29331
  file:
    path: /home/deploy/.ssh/known_hosts
    owner: deploy
    group: deploy
    mode: 0644

- name: Clone repo with --mirror
  environment:
    GIT_SSH_COMMAND: ssh -i /home/deploy/.ssh/id_rsa # Needs git 2.3 + for this to work
  command: git clone --mirror git@github.com:foo/bar.git /path/to/repo
  sudo_user: deploy
这感觉还不错。拥有镜像选项仍然是一件好事

编辑:发言太早,看起来“已知主机”模块更改了文件权限:(现在感觉更糟了

- name: Add githubs key to known hosts
  known_hosts:
    path: /home/deploy/.ssh/known_hosts
    name: github.com
    key: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
    state: present
  sudo_user: deploy

- name: change the owner of the known_hosts file to deploy user
# because https://github.com/ansible/ansible/issues/29331
  file:
    path: /home/deploy/.ssh/known_hosts
    owner: deploy
    group: deploy
    mode: 0644

- name: Clone repo with --mirror
  environment:
    GIT_SSH_COMMAND: ssh -i /home/deploy/.ssh/id_rsa # Needs git 2.3 + for this to work
  command: git clone --mirror git@github.com:foo/bar.git /path/to/repo
  sudo_user: deploy