【发布时间】:2018-01-08 03:09:45
【问题描述】:
你如何通过 ansible 2.4 中的 git 模块做到这一点?
我查看了 doco http://docs.ansible.com/ansible/latest/git_module.html 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
我喜欢漂亮的配置开关来接受主机密钥等。 我认为的替代方案是这样的..(尚未测试)
- name: Test if github is a known host
shell: ssh-keygen -l -f /home/deploy/.ssh/known_hosts -F github.com
register: github_host_is_known
sudo_user: deploy
ignore_errors: True
changed_when: github_host_is_known.rc != 0
- name: Add githubs key to known hosts
shell: ssh-keyscan -H github.com >> /home/deploy/.ssh/known_hosts
when: github_host_is_known.rc != 0
sudo_user: deploy
- name: "Clone repo"
command: git clone --mirror git@github.com:foo/bar.git /path/to/repo
sudo_user: deploy
when: repo_created.changed
这是我唯一/最好的选择吗?
【问题讨论】: