호스트의 SSH 키를 사용하여 Vagrant VM 내에서 개인 저장소를 복제하는 방법은 무엇입니까?

호스트의 SSH 키를 사용하여 Vagrant VM 내에서 개인 저장소를 복제하는 방법은 무엇입니까?

PuppetLabs를 사용하여 공개 git 저장소를 복제할 수 있지만 vcsrepo호스트의 SSH 키를 사용하여 개인 저장소도 복제할 수 있기를 바랍니다.

이를 달성하기 위한 구성은 Vagrantfile어떤 모습입니까 ?manifests/default.pp

답변1

Puppet 부분에 대해서는 도움을 드릴 수 없지만 다음을 설정하여 SSH 에이전트를 전달할 수 있습니다.

Vagrant.configure("2") do |config|
  config.ssh.forward_agent = true
  # ...
end

이런 방식으로 SSH 연결(git으로도 연결)은 호스트의 개인 키를 사용하려고 시도합니다.

답변2

내 컴퓨터에서 작동합니다!

방랑 파일:

VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = 'precise64'
  config.vm.box_url = 'http://files.vagrantup.com/precise64.box'

  #
  # Use host authenticaton for git and maven.
  #
  # Ensure host private key is registered with host SSH agent:
  #
  # ssh-add -L
  # ssh-add ~/.ssh/id_rsa
  # ssh-add -L
  #

  config.ssh.private_key_path = ['~/.vagrant.d/insecure_private_key', '~/.ssh/id_rsa']
  config.ssh.forward_agent = true

  config.vm.synced_folder "~/.m2", "/home/vagrant/.m2"

  config.vm.provision :shell, path: 'upgrade-puppet.sh'

  # Install puppet modules
  config.vm.provision :shell, path: 'bootstrap.rb', args: %w(
    puppetlabs-stdlib
    puppetlabs/apt
    puppetlabs/vcsrepo
  )

  config.vm.provision :puppet do |puppet|
    puppet.options = ENV['PUPPET_OPTIONS']
  end
end

업그레이드-puppet.sh:

#!/bin/bash

apt-get install --yes lsb-release > /dev/null
DISTRIB_CODENAME=$(lsb_release --codename --short)
DEB="puppetlabs-release-${DISTRIB_CODENAME}.deb"
DEB_PROVIDES="/etc/apt/sources.list.d/puppetlabs.list" # Assume that this file's existence means we have the Puppet Labs repo added

if [ ! -e $DEB_PROVIDES ]
then
    # Print statement useful for debugging, but automated runs of this will interpret any output as an error
    # print "Could not find $DEB_PROVIDES - fetching and installing $DEB"
    wget -q http://apt.puppetlabs.com/$DEB
    sudo dpkg -i $DEB
fi
sudo apt-get update > /dev/null
sudo apt-get install --yes puppet > /dev/null

mkdir -p /etc/puppet
touch /etc/puppet/hiera.yaml

bootstrap.sh:

#!/usr/bin/env ruby

modules_dir = '/etc/puppet/modules'

puts `mkdir -p #{modules_dir}` unless File::exists? modules_dir

mods = ARGV

installed = `puppet module list`.split "\n"

mods.each do |mod|
  puts `puppet module install #{mod}` unless installed.any? { |i| i.include?(mod.sub('/','-')) }
end

매니페스트/default.pp:

exec { 'ssh know github':
  command => 'ssh -Tv [email protected] -o StrictHostKeyChecking=no; echo Success',
  path    => '/bin:/usr/bin',
  user    => 'vagrant'
}

vcsrepo { '/home/vagrant/a-private-repo':
  ensure   => latest,
  provider => git,
  source   => '[email protected]:mcandre/a-private-repo.git',
  user     => 'vagrant',
  owner    => 'vagrant',
  group    => 'vagrant',
  require  => Exec['ssh know github']
}

답변3

provisioners/shell/application.setup.sh나는 당신이 Puppet을 사용하고 있다는 것을 알고 있지만 다음 bash 스크립트( ) 를 사용하여 Puppet을 시작하고 실행했습니다 .

#!/bin/bash

local_user=vagrant

if [ ! -n "$(grep "^bitbucket.org " /home/$local_user/.ssh/known_hosts)" ]; then 
    ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null;
fi

if [[ ! -d "/home/$local_user/app" ]]; then
    git clone [email protected]:czerasz/some-app.git /home/$local_user/app

    chown -R $local_user:$local_user /home/$local_user/app

    su - $local_user -c "source /usr/local/bin/virtualenvwrapper.sh && mkvirtualenv some-env && workon some-env && pip install -r /home/$local_user/app/requirements.txt"
fi

꼭두각시 매니페스트로 쉽게 변환할 수 있습니다.

이와 함께Vagrantfile

config.vm.define "web1", primary: true do |web1_config|
    web1_config.ssh.forward_agent = true

    # Create a private network, which allows host-only access to the machine
    web1_config.vm.network "private_network", ip: "192.168.11.10"
    web1_config.vm.hostname = "web1.#{domain}"

    web1_config.vm.provision "shell", path: "provisioners/shell/python.setup.sh"
    web1_config.vm.provision "shell", path: "provisioners/shell/application.setup.sh"
end

나에게 중요한 점은 내가 실행했을 때였습니다.

su - $local_user -c "ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null;"
su - $local_user -c "git clone [email protected]:czerasz/some-app.git /home/$local_user/app"

그것은 효과가 없었습니다. 마치 su. 그래서 저장소를 루트로 복제한 다음 나중에 소유권을 변경했습니다.

이 게시물매우 도움이 되었습니다.

관련 정보