从本地git存储库部署应用程序

这是一个双重的问题。

在git存储库不可公开访问的情况下,我可以使用本地硬盘上的存储库副本(例如主服务器上的副本)从本地机器(也可以运行Ansible)将其部署到删除主机)?

如果对上一个问题的答案是肯定的,git模块是用于这个目的的吗?

编辑:

到目前为止,

目录结构如下:

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部署到一个stream浪的盒子会导致:

 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.", ...} 

Ansible git模块使用本地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挂载目录(这相当于第一种方法)。