簡體   English   中英

如何在microsoft windows下使用ansible克隆git存儲庫

[英]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模塊:

https://github.com/tivrobo/ansible-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM