chefメモ

CentOS7にChef server 12をインストール

file /etc/opscode/pivotal.pem is missing.

というエラー (https://github.com/chef/chef-server/issues/727)

-> cp /opt/opscode/embedded/service/omnibus-ctl/spec/fixtures/pivotal.pem /etc/opscode/

No resource, method, or local variable named `create_stop_system_service' for `Chef::Provider::MysqlService エラー

http://stackoverflow.com/questions/31051890/chef-failed-to-install-mysql-no-resouce-method-or-variable-named-createに対策が書いてあった。私の場合、alb2_installのrecipeを変更した

以下のエラーがでたが、chef-server-ctl reconfigureしたら解決した。

(install chef-manageの後で chef-server-ctl reconfigureを実行しなかったのが原因と思われる)

注意:pivotalというユーザは削除してはならないらしい。

[root@alb Downloads]# chef-server-ctl user-create anagix Joe Anagix support@anagix.com 'xxxxxxxxxxxx' --filename /home/anagix/chef/anagix.pem

ERROR: Failed to authenticate to https://127.0.0.1:443 as pivotal with key /etc/opscode/pivotal.pem

Response: Failed to authenticate as 'pivotal'. Ensure that your node_name and client key are correct.

次にorgとvalidatorを作る

chef-server-ctl org-create anagix 'Anagix Corporation' --association_user anagix --filename /home/anagix/chef/anagix-validator.pem

参考:[Chef12]Chef-Serverの設定

適当にclient.rbをつくってchef-clientを実行したところ以下のエラー

Authentication Error:

---------------------

Failed to authenticate to the chef server (http 401).

原因は、

chef_server_url 'https://alb.anagix.com/

としていたこと。managerにWEBで入り、Administration->Organizations->Generate Knife Configしたらわかった

client.rbを以下のようにしたら動いた

log_level :info

log_location STDOUT

chef_server_url 'https://alb.anagix.com/organizations/anagix'

validation_client_name 'anagix-validator'

validation_key '/etc/chef/anagix-validator.pem'

node_name 'restore'

ssl_verify_mode :verify_none

client_key '/Users/anagix/.chef/client.pem'

knife cookbook upload -a で、以下のエラー

ERROR: You authenticated successfully to https://alb.anagix.com/organizations/anagix as restore but you \

are not authorized for this action

Response: missing create permission

knife.rbのnode_name をanagix、client_keyをanagix.pemにしたらエラーしなくなった。

普通のnodeのknife.rbの場合、knife cookbook uplaod -a --user anagix --key ~/.chef/anagix.pem でもよい

omnibus installer:

curl -L https://www.chef.io/chef/install.sh | sudo bash

mysql cookbook(v6.0.3)をLinuxMint 17.1で使おうとしてはまった(未解決)

しばらくmysqlをアップデートしてなかったので、 仕様がまったく変わっていた。

以前は、LWRPではなかったように思う。 それはさておき本題。

linuxmint 17.1では、ohaiが 以下をかえす。

platform = 'linuxmint'

platform_family = 'debian'

platform_version = '17.1'

mysqlでは、ubuntu(10.04-14.04と14.10とdebianしかサポートしてない。

helpers.rbで、以下とかやってみた:

@pkginfo.set['debian']['17']['5.5']['client_package'] = %w(mysql-client libmysqlclient-dev)

def keyname_forで、return '7' if platform == 'linuxmint'

return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 17

/spec/mysql_service/debian/linuxmint_70_service_55_multi_spec.rb も作ってみたけどダメ。

chef-clientが以下のエラーで止まる:

No resource, method, or local variable named `create_stop_system_service' for `Chef::Provider::MysqlService ""'

Cookbook Trace:

---------------

/var/chef/cache/cookbooks/mysql/libraries/provider_mysql_service.rb:37:in `block in <class:MysqlService>'

とりあえずgive up。

chef 12 clientでは、SSL証明書を使うようになった

/var/opt/chef-server/nginx/caの下に home.anagix.com.crtというのがあるから

これをinstall.anagix.com.crtにrenameして利用者に渡せばいいっぽい。

利用者は、そのファイルを c:\chef\trusted_certs の下に置く。ディレクトリは

自分で作ってもらう。

Windows版chef 12 clientでは、rubyのバージョンが2に上がった(これまでは1.9.3)。

12.0.3では、ruby 2.0.0p451だった。

redmine installation

1. Used chef's ruby (/opt/chef/embedded/bin/ruby)

export PATH=/opt/chef/embedded/bin:$PATH

2. gem install rmagick --no-ri --no-rdoc failed

yum install ImageMagick-devel

setenv PKG_CONFIG_PATH /usr/lib/pkgconfig

backup serverの立ち上げ

1. 以下のようなknife.rbを作る

log_level :info

log_location STDOUT

node_name 'restore'

client_key '/Users/anagix/.chef/client.pem'

validation_client_name 'chef-validator'

validation_key '/Users/anagix/.chef/chef-validator.pem'

chef_server_url 'https://backup.anagix.com'

cache_type 'BasicFile'

cache_options( :path => '/Users/anagix/.chef/checksums' )

cookbook_path [ "/Users/anagix/chef-repo/cookbooks" ]

chef-validator.pemはbackup serverからもってくる。

2. chef-client -c knife.rb を実行

client.pemが作られる

3. webuiで、ノード(この場合restore)をadminにかえる

4. HOMEで、knife backup restoreを実行

以下のようなエラーが出た

=== Restoring cookbooks ===

Restoring cookbook alb_install

Uploading alb_install [0.1.15]

ERROR: Cookbook alb_install depends on cookbook mysql version >= 0.0.0,

ERROR: which is not currently being uploaded and cannot be found on the server.

5. backup serverで、chef-server-ctl reconfigure を実行

その前に、/etc/hostsを以下のように設定するのがミソかも知れない:

127.0.0.1 backup.anagix.com tomoko localhost.localdomain localhost

::1 localhost6.localdomain6 localhost6

192.168.0.228 backup.anagix.com tomoko

注意:127.0.0.1の行で、backup.anagix.com はlocalhostxxxより前でなくてはならない

6. cookbook は入れなおす

chef-repoで、knife cookbook upload -a

7. 再度、knife backup restoreを実行するとエラーは出なかった(cookbookは入れなおしていたので当然か)

以上

vagrantでv-rootがマウントされない

mount -t vboxsf v-root /vagrant

/etc/init.d/vboxadd setup (guest additionsがあたらしくなってkernel moduleのコンパイルが必要な場合)

ubuntuでパッケージが見つからない場合

apt-get update する

Vagrantでboxが古くなっている場合は、

ユーザrubyへのgemのインストール

Installing gems in a new Chef system Ruby during the Chef Run

# Need to reload OHAI to ensure the newest ruby is loaded up

ohai "reload" do action :reload end ["bundler", "rake", "...."].each do |gem_to_install| ruby_block "install #{gem_to_install} in new ruby" do block do g = Chef::Resource::GemPackage.new(gem_to_install) g.gem_binary "#{node['languages']['ruby']['bin_dir']}/gem" g.run_action(:install) end action :create end end

mysqlのルートパスワード

自動生成されたものが、/etc/mysql/grant.sql に記録されている

mysql serverが入らないときの recipe

recipe[mysql::server]

古いlinux kernel (2.6.30以前らしい)で、shefなどが止まる問題の対策

centos4.8(32bit, kernel 2.6.9-89)で対策したが、centos5(64bit, kernel 2.6.18)では必要なかったのでよくわからん

対策: lib/ohai/plugins/linux/[memory.rb, uptime.rb]で以下のように修正した

#File.open("/proc/meminfo").each do |line|

`/bin/cat /proc/meminfo`.each_line do |line|

#uptime, idletime = File.open("/proc/uptime").gets.split(" ")

uptime, idletime = `/bin/cat /proc/uptime`.split(" ")

参考:Files in /proc should not be read directly by Ruby rubyで既知の問題のようだ

Fix for older linux kernels and blocking read of /proc/* files in virtualization plugin ohaiでも指摘されているがohai-6.16.0時点で修正されてない