LoginSignup
35
37

More than 5 years have passed since last update.

AnsibleからVagrantにssh経由でgit cloneする時の注意点

Last updated at Posted at 2014-11-13

概要

以下のようなケースはSSH経由でGitHubのソースをダウンロードする必要があります。

  1. 秘密鍵にパスフレーズが設定されている!
  2. GitHubのアカウントが2段階認証になっている!
  3. git操作するたびにパスワード入れるのが面倒!
  4. 環境自動構築ツールでgit cloneさせたい

今回のブログはケース4に焦点を当てて説明をしたいと思います。筆者の作業環境は

  • macosx 10.10
  • Ansible 1.7.2
  • Vagrant 1.6.5

次、作業ポイントについて説明させていただきます。

手順1. ローカル環境に認証鍵を登録

# sshエージェント起動
ssh-agent

# ssh-add [秘密鍵の格納場所]
ssh-add ~/.ssh/id_rsa

# 登録確認
ssh-agent -l

手順2. VagrantのSSH Agent Forwarding設定を有効にする

Vagrantfileを修正

# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
config.ssh.forward_agent = true

仮想環境起動(vagrant up)

手順3. plyabookにgit cloneの記述をする

playbook記述

- name: Copy the code from repository
  git: repo={{ repository }} dest=/home/vagrant/repo1 accept_hostkey=yes
  sudo: no

ansible-playbook -i host [playbook名] でansible実行

35
37
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
37