Chef周りのメモ2
Vagrantで作成した仮想環境のSSHポートを変更したい
vi /etc/ssh/ssh_config
#Port 22 ↓ Port 19999
/etc/init.d/sshd restart
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT ↓ -A INPUT -m state --state NEW -m tcp -p tcp --dport 19999 -j ACCEPT
/etc/init.d/sshd restart
- 仮想環境から抜ける
- 仮想環境の停止
- すでに22番ポートにはつながらないので-f必須
vagrant halt -f
- Vagrantfileでポートフォワードの設定を変更
vi Vagrantfile
config.ssh.guest_port = 19999 config.vm.network :forwarded_port, guest: 19999, host: 2222, id: "ssh", auto_correct: true
- 仮想環境の起動
vagrant up
以上!
特定のcookbookのみ実行する
knife solo cook HOSTNAME -o iptables
iptablesこわい
/etc/rc.d/init.d/iptables stop
ってやってるのにiptablesを設定するシェルを実行すると
iptables -P OUTPUT DROP
を実行したところでサーバーが応答しなくなってしまう。
実は、iptablesコマンドを実行したらiptablesを止めていてもまた起動してしまうようだ。設定も即反映。
解決策は上記コマンドの実行前にSSHは通すように設定するか、OUTPUTはACCEPTにするか。
また、こんな失敗に備えてvagrant-vbox-snapshotを入れておく。
saharaより戻すのが早くて便利。
nodeのjsonファイルでattributesを設定する
こう設定して
{ "ssh_port":19999, "run_list":[ .... ] }
こう使う(templateファイルの場合)
iptables -A INPUT -i eth0 -p tcp -m state --state NEW --dport <%= node[:ssh_port] %> -j ACCEPT_COUNTRY iptables -A OUTPUT -o eth0 -p tcp ! --syn -m state --state ESTABLISHED --sport <%= node[:ssh_port] %> -j ACCEPT_COUNTRY
NoMethodError: undefined method `run_list_for' for {"run_list"=>["recipe[security]"]}:Hash
今までnodeに書いていた設定をroleにまとめ、roleをnodeで読みこむようにしたら発生。
nodeの内容はそのままroleに移すことはできないらしい。
下記のように修正してエラー解消。
{ "run_list":[ "recipe[security]" ] }
↓
{ "json_class":"Chef::Role", "run_list":[ "recipe[security]" ] }
ERROR: RuntimeError: Couldn't find Chef >=0.10.4 on HOSTNAME. Please run `knife solo prepare USERNAME@HOSTNAME` to ensure Chef is installed and up to date.
いろいろな理由で出るエラーのようだけど…。
私の場合はUSERNAME@HOSTNAMEにsudo権限がないのが原因でした。
/etc/sudoers.d/以下に設定を追加してエラー解消。
sshで公開鍵認証でログインできるのに、knife solo実行時にパスワードを聞かれる
knife soloによるchef soloはsudoを使用して実行されるため、sudoをパスワードなしで実施できるように設定していない限り、sudoのためのパスワードを聞かれる。
ERROR: RuntimeError: Failed to launch command rsync -rl --rsh="ssh USERNAME@HOSTNAME" --delete --exclude 'revision-deploys' --exclude 'tmp' --exclude '.git' --exclude '.hg' --exclude '.svn' --exclude '.bzr' /Users/xxxxx/xxxxx/chef-repo/cookbooks/ :~/chef-solo/cookbooks-1
knife solo prepare HOSTNAMEを実施し忘れている。
穴という穴に嵌っている気がしますが
適当にやってるからそうなる。