Itamaeを使ってUbuntuサーバにNginxをインストール・起動する

前提

  • サーバ
  • クライアント
  • Macの各種バージョン
    • Ruby
      • 2.3.3
    • gem
      • 2.5.2
    • Itamae
      • 1.9.10

Itamaeをインストール

gem install itamae

Nginxをインストールし起動するレシピを作成

# nginx_recipi.rb
execute "install nginx" do
  command "sudo apt-get -y install nginx"
end
execute "nginx start" do
  command "sudo /etc/init.d/nginx start"
end

Itamaeを実行

itamae ssh -h hostname -p 22 -u username nginx_recipi.rb -l debug
INFO : Starting Itamae...
DEBUG : Executing `mkdir -p /tmp/itamae_tmp`...
DEBUG :   exited with 0
DEBUG : Executing `chmod 777 /tmp/itamae_tmp`...
DEBUG :   exited with 0
.
.
.
DEBUG :       (in set_current_attributes)
DEBUG :       (in show_differences)
 INFO :       execute[nginx start] executed will change from 'false' to 'true'
Executing `sudo /etc/init.d/nginx start`...

上記のようなコードが出ていたら成功。

サーバにアクセスしてNginxが起動していることを確認する。

ホスト名をexample.comと仮定した場合、ブラウザで http://example.com にアクセスして
f:id:poustel:20170121185647p:plain
が出ていたら成功。