好的…我們 Vagrant 練習過, Ansible 也練習過
Vagrant 是快速建立 VM, Ansible 是快速初始化及管理 VM
兩個怎麼都在一起練習呢?
我們來試驗一下
回顧
沒有練習過的回去看這兩篇
Ansible 安裝及入門
Vagrant introduction
建立適合的 Vagrantfile
Vagrantfile1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32# -*- mode: ruby -*-
# vi: set ft=ruby :
NODE_COUNT = 2
Vagrant.configure("2") do |config|
# Don't auto update VirtualBox Guest Additions
config.vbguest.auto_update = false
config.vm.define "myvm" do |myvm|
myvm.vm.box = "centos/7"
myvm.vm.network :private_network, ip: "192.168.56.10"
# myvm.vm.synced_folder "/github", "/tmp/github"
myvm.vm.provision :shell, inline: <<-SHELL
sudo yum install epel-release -y
sudo yum update -y
sudo yum install python-pip -y
sudo pip install --upgrade pip
sudo yum install ansible -y
SHELL
end
NODE_COUNT.times do |i|
node_id = "node#{i}"
config.vm.define node_id do |node|
node.vm.box = "centos/7"
node.vm.hostname = "#{node_id}.intranet.local"
node.vm.network :private_network, ip: "192.168.56.#{20+i}"
end
end
end
After run vagrant up
1 | $ vagrant up |
you can see myvm has ansible and fixed IP.
SAM的程式筆記 由朱尚禮製作,以創用CC 姓名標示-非商業性-相同方式分享 4.0 國際 授權條款釋出。