LoginSignup
4
4

More than 5 years have passed since last update.

Tips : Vagrantfileでproxyを設定する

Posted at

こんにちは。

以前、proxy下でVagrant+knife-soloしちゃおうという記事を投稿しましたが、その感想で「わざわざsshで繋いでproxyの設定しなくちゃいけないじゃん 何が自動化だ めんどくせ」と文句を垂れていました。

ちょっと挑戦してみたところ、Vagrantfileでシェルスクリプトが実行出来るということを知ったので、ここでプロキシ設定してみました。

やり方

Vagrantfileに以下を追加するだけ。

Vagrantfile
Vagrant.configure("2") do |config|
...

  $script = <<-SCRIPT
    input_file=/etc/environment
    output_file=/etc/tmpenvironment

    sed -e "/^http_proxy/d" -e "/^https_proxy/d" -e "/^no_proxy/d" $input_file > $output_file
    echo 'http_proxy="http://SERVER:PORT"\nhttps_proxy="https://SERVER:PORT"\nno_proxy="192.168.*.*"' >> $output_file
    mv $output_file $input_file
  SCRIPT

  config.vm.provision :shell,
    :inline => $script

...
end

シェルスクリプトというものを初めて書いたので、美しい書き方かどうか不明ですが、一応これで動いています。

これで、少し手間が省けました。

4
4
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
4
4