[英]How to clone git repository using ansible under microsoft windows
Ansible 2.1,centos7下控制主机,windows 10作为客户端的数量。
我需要在远程端克隆 git 存储库,但不知道如何执行此操作:
我试过这样的事情:
- name: clone repositories
git:
repo: "{{ item.repo }}"
dest: "C:\openserver\domains\{{ domain_name }}\{{ item.value.path }}"
version: "{{ item.version | default('HEAD') }}"
with_items: "{{ repositories }}"
我从@tivrobo 找到了要使用的win_git
模块:
如果不是太晚,你可以使用这样的东西
- name: clone repositories
win_command: >
"C:\Program Files\Git\bin\git.exe"
"--no-pager"
"clone"
"http://user:pass@github.com/OpenCorpora/opencorpora.git"
"C:\OPenserver\domains\opencorpora.local\www"
"--branch"
"master"
"--recursive"
参考https://docs.ansible.com/ansible/latest/user_guide/windows_usage.html
Ansible 建议使用脚本模块,我使用原始模块代替(这种方式是否不如脚本模块安全?):
- name: clone repositories
raw: C:\OpenServer\modules\git\cmd\git.exe clone https://github.com/OpenCorpora/opencorpora.git C:\OPenserver\domains\opencorpora.local\www
先决条件:已安装 msysgit(在我的情况下为C:\\OpenServer\\modules\\git\\
),或用于 Windows 的本机 git 客户端(请参阅此处: https ://git-scm.com/download/win)
PS 不幸的是,我今天不知道如何使用具有默认安装路径(带空格)的本机客户端:
- name: clone repositories
raw: C:\Program Files\Git\cmd\git.exe clone https://github.com/OpenCorpora/opencorpora.git C:\OPenserver\domains\opencorpora.local\www
它失败并出现错误:
TASK [website_win : clone repositories] ****************************************
fatal: [192.168.1.43]: FAILED! => {"changed": false, "failed": true, "rc": 1, "stderr": "C:\\Program : The term 'C:\\Program' is not recognized as the name of a cmdlet, function, script file, or operable progra\r\nm. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.\r\nAt line:1 char:1\r\n+ C:\\Program Files\\Git\\cmd\\git.exe clone https://github.com/OpenCorpora ...\r\n+ ~~~~~~~~~~\r\n+ CategoryInfo : ObjectNotFound: (C:\\Program:String) [], CommandNotFoundException\r\n+ FullyQualifiedErrorId : CommandNotFoundException\r\n", "stdout": "", "stdout_lines": []}
NO MORE HOSTS LEFT *************************************************************
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.