vagrant_configyaml - choisungwook/portfolio GitHub Wiki

개요

  • vagrant에서 yaml파일 로드
  • 주로 설정파일을 yaml파일에 설정할 때 유용하다.

세부 내용

  • config.yaml은 vagrant와 같은 경로에 존재해야 한다.
  • vagrant는 yaml 라이브러리를 로드해야 한다.

config.yaml

---
server1:  
  name: server1
  box: centos/7
  hostname: test-server1
  ip: 192.168.25.188"
  memory: 2048
  cpu: 2

vagrant

require 'yaml'

CONFIG = YAML.load_file(File.join(File.dirname(__FILE__), 'config.yml'))

Vagrant.configure("2") do |config|
  config.ssh.insert_key = false

  config.vm.define CONFIG['server1']['name'] do |cfg|
    cfg.vm.box = CONFIG['server1']['box']
    cfg.vm.network "public_network", ip: CONFIG['server1']['ip']
    cfg.vm.hostname = CONFIG['server1']['hostname']
    
    cfg.vm.provider "virtualbox" do |v|
      v.memory = CONFIG['server1']['memory']
      v.cpus = CONFIG['server1']['cpu']
      v.name = CONFIG['server1']['hostname']
    end
  end
end

참고자료

⚠️ **GitHub.com Fallback** ⚠️