這是一個雙重問題。
在 git 儲存庫不可公開存取的情況下,我可以使用硬碟上儲存庫的本機副本(或主伺服器上的副本,例如)從本機電腦(也執行 Ansible)部署到刪除主機)?
如果上一個問題的答案是肯定的,那麼 git 模組是否用於此目的?
編輯:
到目前為止我嘗試過的:
dir架構如下:
repo/
|-.git/
|-deploy/
| |-inventory
| |-roles/
| | \-app/
| | \-main.yml
| \-vagrant.yml
\-src/
劇本包含:
- name: Clone local application
git: repo={{ inventory_dir }}/../
dest=/home/{{ application_name }}/code
透過 SSH 將其部署到 vagrant box 會導致:
fatal: [vagrant]: FAILED! => {
"changed": false,
"cmd": "/usr/bin/git clone --origin origin path/to/repo",
"failed": true,
"msg": "Cloning into '/home/app/code'...\nfatal:
'path/to/repo' does not appear to be a git repository\nfatal:
Could not read from remote repository.\n\nPlease make sure you
have the correct access rights\nand the repository exists.",
...}
答案1
Ansiblegit
模組使用本機git
可執行檔來執行其操作,因此您需要像手動操作一樣繼續操作。
將包含 Git 儲存庫的磁碟掛載到目標電腦。
如果您將儲存庫保存在包含的目錄下
Vagrantfile
(這可能與您的場景不同 - 不確定您的意思vagrant.yml
),那麼使用 Vagrant 可以輕鬆實現這一點。Vagrant 預設會在
/vagrant
虛擬機器中掛載此目錄,因此要複製儲存庫,您可以使用標準git
模組:- git: repo: /vagrant/path/to/source/repository dest: /path/to/destination
它將把存儲庫克隆到
/path/to/destination/repository
.使用 Ansible
synchronize
模組將儲存庫推送到目標電腦。如果克隆的唯一原因是「部署應用程式」而不推回到原始儲存庫,那就足夠了。最後,您可以使用 Git 支援的任一協定共用儲存庫,例如 SSH、HTTP、HTTPS、FTP、FTPS、rsync;或使用 NFS 掛載目錄(這相當於第一種方法)。