vagrantでroleを扱う
今年はこまめにBlogを書いていこうと思います。
さて、只今絶賛chefと遊んでおり、レシピを書くのにVagrantを利用しています。
VagrantでRoleを利用するのは簡単でした。
1. Vagrantfileの編集
今回はrole[web-server]と[db-server]として稼働するように設定してみます。
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant::Config.run do |config| ・・省略・・ config.vm.provision :chef_solo do |chef| ・・省略・・ chef.roles_path = "<role用json保管ディレクトリ名>" chef.add_role("web-server") chef.add_role("db-server") end end
2.role定義ファイル保管ディレクトリ作成
$ mkdir <role用json保管ディレクトリ名>
3.roleの作成
WebサーバとDBサーバのロールを作成します。
# web-server.json { "name": "web-server", "chef_type": "role", "json_class": "Chef::Role", "default_attributes": { "httpd": { "listen_ports": [ "80","443" ] } }, "description":"The Role is Web Server TEST", "run_list": [ "recipe[apache]" ], "env_run_lists": { } } # db-server.json { "name": "db-server", "chef_type": "role", "json_class": "Chef::Role", "default_attributes": { "mysqld": { "port": [ "3306" ], "log_bin": [ "no" ] } }, "description":"The Role is DB Server TEST", "run_list": [ "recipe[mysql]" ], "env_run_lists": { } }