これは2つの側面を持つ質問です。
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 ボックスにデプロイすると、次のようになります。
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 リポジトリを含むディスクをターゲット マシンにマウントします。
これは、リポジトリを を含むディレクトリの下に保存しておけば、Vagrant で簡単に実現できます
Vagrantfile
(これはシナリオとは異なる可能性があります - の意味がわかりませんvagrant.yml
)。Vagrant はデフォルトでこのディレクトリを
/vagrant
仮想マシンにマウントするため、リポジトリをクローンするには標準モジュールを使用しますgit
。- git: repo: /vagrant/path/to/source/repository dest: /path/to/destination
リポジトリを にクローンします
/path/to/destination/repository
。Ansibleを使用する
synchronize
モジュールリポジトリを宛先マシンにプッシュします。クローンの唯一の理由が、元のリポジトリにプッシュバックせずに「アプリケーションをデプロイする」ことである場合、これで十分です。最後に、SSH、HTTP、HTTPS、FTP、FTPS、rsync など、Git でサポートされているプロトコルのいずれかを使用してリポジトリを共有するか、NFS を使用してディレクトリをマウントします (これは最初の方法と同等です)。