ときどきAnsible日記

主にITインフラ基盤の自動化に関する事を書いているブログです

Vagrantを使ってみる

お疲れ様です。伊藤です。


自動化について調べていくとVagrant(ベイグラント)によくあたります。要はVirtualBoxを使った仮想マシンの作成→OSインストールがすべてワンクリックで出来る!というものらしいです。よくわかってなかったのでこれを機に使ってみたいと思います。


まずは公式HPからダウンロード。
www.vagrantup.com

で、ダウンロードしたファイルをクリックしてインストール。ここで注意!インストール後強制的にWindowsが再起動されます。うかつに進めると再起動走るので注意してください。(この記事も消えかけた)


インストール後は下記からBoxファイルというOSイメージが入ったファイルをダウンロード
https://atlas.hashicorp.com/search
って、ちょっとこれは怖いので今回はやめておきます。OSイメージとかは正規のものを用意して、自前でBoxファイルを作ります。


とりあえずVirtualBoxを起動して、いったんRHEL7.3をインストールした仮想マシンを用意します。それを基にBoxファイルを作成していきましょう。
仮想マシン構築部分は割愛~
実際には↑の作業は20~30分かかるのでこの作業がどれくらいに短縮できるかは楽しみです。


仮想マシンの用意が終わりました。仮想マシン名はrhel7_3です。
では早速Vagrantを動かしていきます。
まずはインストール確認

C:\Users\test>vagrant -v
Vagrant 1.9.7

無事インストールされているようです。

続いてVagrant用のディレクトリを作成

C:\Users\test>mkdir C:\Vagrant & cd C:\Vagrant
C:\Vagrant>
C:\Vagrant>mkdir rhel73 & cd rhel73
C:\Vagrant\rhel73>

Boxファイルがない事を確認

C:\Vagrant\rhel73>vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.

Boxファイル作成

C:\Vagrant\rhel73>vagrant package --base rhel7_3
==> rhel7_3: Exporting VM...
==> rhel7_3: Compressing package to: C:/Vagrant/rhel73/package.box

ちょっと時間がかかりますがこれでBoxファイルが出来ました。
package.boxというファイルが530Mbyteでできています。

これをVagrantに登録

C:\Vagrant\rhel73>vagrant box add --name rhel7.3-x86_64-ja-20170802 package.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'rhel7.3-x86_64-ja-20170802' (v0) for provider:
    box: Unpacking necessary files from: file://C:/Vagrant/rhel7_3/package.box
    box: Progress: 100% (Rate: 890M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'rhel7.3-x86_64-ja-20170802' (v0) for 'virtualbox'!

上手く行ったっぽい。-nameのあとの名前は適当です。

C:\Vagrant\rhel73>vagrant box list
rhel7.3-x86_64-ja-20170802 (virtualbox, 0)


これを基にVagrantファイルを作成。

C:\Vagrant\rhel73>vagrant init rhel7_3
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Vagrantfileというファイルが出来ました。早速マシンを作って起動してみましょう。
f:id:pj_doaa:20170802112433p:plain

その前に先ほど作った仮想マシンは削除して。。。。実行!

C:\Vagrant\rhel73>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'rhel7_3' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'rhel7_3' (v0) for provider: virtualbox
    default: Downloading: rhel7_3
    default:
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

Couldn't open file /C:/Vagrant/rhel73/rhel7_3

あれえ。。。
なんかファイルが開けないって言われました。どうやら先ほどのpackage.boxを
rhel7_3という名前で読みに行きたい様子。ファイル名を変更して再開!
f:id:pj_doaa:20170802112508p:plain

C:\Vagrant\rhel73>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'rhel7_3' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'rhel7_3' (v0) for provider: virtualbox
    default: Unpacking necessary files from: file://C:/Vagrant/rhel73/rhel7_3
    default: Progress: 100% (Rate: 972M/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'rhel7_3' (v0) for 'virtualbox'!
==> default: Importing base box 'rhel7_3'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: rhel7_3_default_1501639887630_57662
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

...なんかタイムアウトになってる。。
おそらくこれは元のマシンがネットワークの設定とかしてないのでsshの設定を勝手にやろうとして失敗している様子。てかVagrantってSSHの設定やっちゃうのね。。

Virtualboxを開いてみるとrhel7_3_default_1501639887630_57662という名前の仮想マシンが出来て起動しています。
とりあえずこれで自動的にマシンを作ることはできました。
時間もかなり短縮されそうです(おそらくマシンを作るだけなら3分ぐらいで終わっている様子)ただし、色々と設定する項目があるようですね。


とりあえず今回は以上です。お疲れ様でした。

インターミッション~イヤホンのはなし~

お疲れ様です。伊藤です。

ちょっとペースが速い気がしますが、小休止です。

昔、仕事場でイヤホンに詳しい方がいらっしゃいまして、そこで色々と教えてもらい結構はまりました。ピーク時には3万ぐらいのイヤホン買ってたっけな。。。。こーゆーの
Amazon CAPTCHA
好きな人からしたら大したことないし、知らない人からしたらなんでそんなに金かけるの?という中途半端なもの。でも個人的には結構気に入ってます。


その後いろいろとあり、現在はbluetoothイヤホンでほとんど過ごしております。iPhone7もイヤホンジャックがなくなったことですし。で、ちょっと前まではbluetoothイヤホン市場はかなり限られたメーカーからしか出てなくて、価格も安くて1万以上みたいな結構法外な値段でした。(今調べてみたら過去のモデルはほとんど見かけないですね)

その後、おそらくbluetoothの技術(てか部品?)がアジア諸国に流れたことにより格安のbluetoothイヤホンが乱立しております。いやあいい時代になった。音質や取り回しもピンキリ。長く持つものもあれば、そっこーで壊れちゃうやつもあります。そこで私が山ほど買った中で個人的に使いやすかったイヤホンをご紹介します。


普通に使うならこのあたりで十分かと。自分が買ったやつはすでに出てないので似たようなやつ。
Mpow Enchanter bluetooth4.1 スポーツイヤホン ワイヤレス ヘッドセット 超軽量13g IPX4防水 IP4X防塵 CVC6.0ノイズ低減の仕組み iPhone&Android スマートフォンに対応 MP-BH053AB
Mpowという謎のメーカーから大量に出ているイヤホンの中でもこのタイプは使いやすいと思います。音質もそこそこ。耳なじみもいい。何より安い。まあ失敗してもいいかなと思える価格です。バッテリーも体感で5~6時間は持った気がします。ちなみに私が買ったやつはすぐ壊れました(多分個体差)


スポーツで使うならこの辺。
ICONNTECHS IT(JP) Bluetoothイヤホン ワイヤレス マイク フック付き ランニング中でも耳から外れにくい スポーツ ランニング 耳掛け式 高音質 防水 防滴 ハンズフリー通話 ノイズキャンセリング搭載 iphone対応 [1年保証付]
これまた謎のメーカーICONNTECHSのU8です。ってか激安イヤホンはすべて謎のメーカーです。今見たら似たようなイヤホンが山ほど出ていますが、そもそもこれもbeatsのパクリだと思います。これもそこそこ音質が良くて、使いやすい。あと耳に引っ掛けるところがゴムでへにょへにょなので長時間使っていても痛くなりません。これもバッテリーは前述のと同じぐらいもちます。(たぶん)


片耳タイプでよければこちら。AngLink C08
【世界最軽量ヘッドセットわずか3.8g】 Bluetooth ヘッドセット V4.1 Bluetooth ワイヤレスヘッドセット 片耳 ブルートゥース ヘッドセット Bluetooth ワイヤレスイヤホン 防汗防水 マイク内蔵 軽量小型 モノラル 高音質 ノイズキャンセリング搭載 iPhone Android などのスマートフォンに対応 by AngLink (ブラック)
これはバッテリーはあまり持たないです。3~4時間といったところ。ただ、このタイプでは珍しく音の通りもよくて聞きやすい。ノイズキャンセルとか謡ってますが期待しちゃいけません。そもそも片耳なのにノイズキャンセルて。


でもほんとに欲しいのはこれ。
Bose SoundSport wireless headphones ワイヤレスイヤホン ブラック【国内正規品】
bosetriportというヘッドホンを使ってたんですが、そこからにわかbose信者です。。。ほすぃ。。。


ただただ、私の物欲をさらしただけになってしまいました。
以上です。お疲れ様でした。