Chef(正確には chef-zero + knife-zero) で、本当に短い Hello World! 的なものを作ってみた。
前提
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!