LoginSignup
6
6

More than 5 years have passed since last update.

vagrantでホストOS上のスクリプトをゲストOSで実行するvagrant-exec

Last updated at Posted at 2014-02-16

Vagrantにはprovisioningという仕組みがありますが、それとは別にゲストOSにスクリプト等で仕事をさせたいケースもあります。そんなときはvagrant-execというプラグインを導入しましょう。

vagrant-exec

導入手順

$ vagrant plugin install vagrant-exec

使い方

コマンド実行する

exec の後に実行したいコマンドを記述でOK

$ vagrant exec pwd

スクリプト(シェル)を実行させる

$ vagrant exec ./hoge.sh

注意点

シェルを実行させる場合の注意点として、スクリプトの改行コードはCRLFではなくLFでなければ実行時にエラーになることである。
ホストOS上のスクリプトをゲスト上で実行するので当たり前なのだが、例えばgit管理してるスクリプトをwindowsユーザーが利用する場合、core.autocrlfの設定に酔ってはでgit clone時にLF→CRLF変換されてしまうので運用面ではかなり注意である。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6