この記事がなければなんもできなかった
まあハマるしエラー出るしansibleが素晴らしいことがよくわかった。
ゲスト側はだいたい言われるままに行った。
こけたのはリモートから操作されるときにrsyncが必要だったことかな。
chef-soloやってるときのhistoryロストしてしまった。。
ゲスト側
[root@kickstart ~]# history
4 chef-solo -v
5 yum install wget -y vim
6 mkdir ~/chef-solo/cookbooks-1
7 cd ~/chef-solo/
8 ll
9 yum install -y rsync
11 mkdir /knife/cookbooks -p
15 yum remove -y dstat
16 mysql -uroot -p
適当にハマったところ端折ってるけどホスト側
nodes/host名.json になることがわからなくてしばしハマった。project作る、project名を nodes/host名.json
の run_list に入れて bundle exec knife solo cook host名
する。
ホスト側から操作する
curl -L https://www.opscode.com/chef/install.sh | sudo bash
mkdir /knife
cd /knife/
bundle init
gem install bundler
bundle init
ll
vim Gemfile
bundle install --path vendor/bundle
ll
# ruby 2.0古すぎ
yum install gcc-c++ patch readline readline-devel zlib zlib-devel -y
yum install libyaml-devel libffi-devel openssl-devel make -y
yum install bzip2 autoconf automake libtool bison iconv-devel sqlite-devel -y
curl -L get.rvm.io | bash -s stable
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
# ruby 2.4なら動いた
rv install 2.4
rvm use 2.4.1 --default
ruby --version
gem install bundler
bundle install --path vendor/bundle
bundle exec knife solo init .
ll
rpm -Uvh https://packages.chef.io/files/stable/2.4.17-1.el7.x86_64.rpm
# 遠隔操作してみる
chef generate cookbook site-cookbooks/dstat dstat
vim site-cookbooks/dstat/recipes/default.rb
bundle exec knife solo cook kickstart
knife bootstrap 192.168.1.100 -N kickstart
bundle update
bundle exec knife solo cook kickstart
vim nodes/kickstart.json
nodes/
└── kickstart.json
# cat nodes/kickstart.json
{
"run_list": [
"recipe[dstat]"
"recipe[mysql]"
],
"automatic": {
"ipaddress": "kickstart"
}
bundle exec knife solo cook kickstart
chef generate cookbook site-cookbooks/mysql mysql
vim site-cookbooks/mysql/recipes/default.rb
vim nodes/kickstart.json
bundle exec knife solo cook kickstart
chef generate cookbook site-cookbooks/nginx nginx
cat site-cookbooks/mysql/recipes/default.rb
bundle exec knife solo cook kickstart
vim site-cookbooks/mysql/recipes/default.rb
vim nodes/kickstart.json
bundle exec knife solo cook kickstart
いやーansibleのほうがよさそうだな・・・
とりあえずserver-clientまでやっておくか・・・
インフラ勉強会でみた chef-DK とはなんぞや