LoginSignup
3
3

More than 5 years have passed since last update.

Docker + Chef で本物の Hello World!

Last updated at Posted at 2016-08-11

Chef(正確には chef-zero + knife-zero) で、本当に短い Hello World! 的なものを作ってみた。

前提

Chef 動作確認用 Docker イメージを使う。

Docker コンテナ起動

Chef ワークステーション(構成管理する側)

$ docker run -it --name chef_ws ubuntu_chef

Chef ノード(構成管理される側)

$ docker run -it --name chef_node ubuntu_chef
# service ssh start
# ifconfig eth0
=> IP アドレスを取得(例:173.17.0.3)

準備するファイル

chef_ws コンテナの適当なディレクトリに置く。

hello.sh
mkdir -p hello
cd hello

echo 'local_mode true' > ./knife.rb

mkdir -p ./cookbooks/hello/recipes
cat > ./cookbooks/hello/recipes/default.rb <<END
file '/tmp/hello.txt' do
  content "Hello World!\n"
end
END

knife zero bootstrap 172.17.0.3 -x root --overwrite
node=`knife node list`
knife node run_list add $node hello
knife zero converge name:$node --attribute ipaddress -x root

Chef 実行

chef_ws で、

# ls
hello.sh
# sh hello.sh

結果確認

chef_node で、

# cat /tmp/hello.txt
Hello World!
3
3
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
3
3