如何在Ansible 2.4中通过git模块实现此操作?
我已经查看了文档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
这是我唯一/最好的选择吗?