Vagrant 使おうとして調べたこととか
Vagrant 使わないとどうなるの?
例えば Ubuntu だとこんだけ初期設定が大変らしい。
こりゃ Vagrant 使うしかねえや。
Box はどれを選べばいいの?
公式ドキュメント(Install and Specify a Box | Vagrant - HashiCorp Learn)を見ると、
Warning: Namespaces do not guarantee canonical boxes, and anyone can publish boxes on Vagrant Cloud. HashiCorp's support team does not assist with third-party published boxes.
とのこと。
公式ドキュメントの他の箇所(Discovering Vagrant Boxes | Vagrant by HashiCorp)では、ユーザ名、ダウンロード数、最終更新日とかを調べるように書いてある。
The username of the user. If it's
bento
orubuntu
, you can likely trust the box more than an anonymous user.
bento は信頼できるらしい。
IP 指定してアクセスしたいんだけど
private_network
、forwarded_port
, public_network
のどれかのネットワークで指定する。
各ネットワークの違いは以下が詳しかった。
とりあえず外部に公開しないなら private_network
で良い。
IP 何にすればええねん
一つの手として DHCP を指定することができる。
動的に変更されるのが嫌なら、何か固定値を指定するしかない。
private_network
ならプライベートネットワーク IP(192.168.XXX.XXX とか)を指定するのが安全だろう。
既存のプライベートネットワーク IP とバッティングしたらどうすんねん
事前に使用済 IP を調べておいて回避するしかない。
LAN内で使用している IP を一覧取得するには、ping を飛ばしまくって確認するしかないっぽい。
まあ、思いついた IP に ping 飛ばしてみて、空いていたらそれを使えばいいだろう。
尚、自マシンが属するのと同じ 192.168.1.XXX
を試しに指定してみたところ、以下のエラーが出て起動に失敗した。
The specified host network collides with a non-hostonly network! This will cause your specified IP to be inaccessible. Please change the IP or name of your host only network so that it no longer matches that of a bridged or non-hostonly network. Bridged Network Address: '192.168.1.0' Host-only Network 'en0: Wi-Fi (AirPort)': '192.168.1.0'
そんなこんなで大きな心配はなさそうだ。
IP の末尾を 1 にしたらなんか警告が出た
==> ansible: This is very often used by the router and can cause the ==> ansible: network to not work properly. If the network doesn't work ==> ansible: properly, try changing this IP.
とのこと。
複数マシンの一括設定ができるらしい
詳しくは公式ドキュメント参照(Multi-Machine | Vagrant by HashiCorp)。
共通の設定を一箇所にまとめつつ、個別の設定は個別に書く、みたいなことができる。
vagrant up
で一括に起動したり、vagrant up <machine>
で個別に起動したり等ができる。
Provisioning って何?なんか Ansible とかあるんだけど
ソフトのインストール作業とかも自動化するやつ。
公式ドキュメントにある Provisioning の "Ansible"(Ansible - Short Introduction | Vagrant by HashiCorp)は、対象仮想マシンを Ansible で初期化するやつだった。
(Ansible をインストールする初期化だと思ったのに、違った。)
そんなこんなでできた Vagrantfile
Ansible で遊ぶために以下の Vagrantfile を作った。
# -*- mode: ruby -*- # vi: set ft=ruby : <200b> Vagrant.configure("2") do |config| config.vm.box = "bento/centos-7" <200b> config.vm.define "ansible", primary: true do |ansible| ansible.vm.network "private_network", ip: "192.168.33.20" end (1..3).each do |n| config.vm.define "node#{n}" do |node| node.vm.network "private_network", ip: "192.168.33.1#{n}" end end end
おわり。