LoginSignup
1
1

More than 5 years have passed since last update.

Chef(bootstrap, knife ssh) - chef-server が target node の default gateway 側に無い場合

Last updated at Posted at 2016-01-05

Workstation から node に Bootstrap した際、Chef Server に登録される node の ip address は
default gateway 側の ip address が選択される。
この状態では Workstation から knife ssh 出来ない。どうしたもんだ。。。

chef_bootstrap.png

Workstation から Bootstrap

[workstation]$ knife bootstrap 10.10.0.10 -x root -N node01 -E lab --sudo
~~ 省略 ~~
Connecting to 10.10.0.10
10.10.0.10 Starting first Chef Client run...
10.10.0.10 Starting Chef Client, version 12.5.1
10.10.0.10 Creating a new client identity for node01 using the validator key.
10.10.0.10 resolving cookbooks for run list: []
10.10.0.10 Synchronizing Cookbooks:
10.10.0.10 Compiling Cookbooks...
10.10.0.10 [yyyy-mm-ddThh:mm:ss+00:00] WARN: Node node01 has an empty run list.
10.10.0.10 Converging 0 resources
10.10.0.10
10.10.0.10 Running handlers:
10.10.0.10 Running handlers complete
10.10.0.10 Chef Client finished, 0/0 resources updated in 13 seconds

Chef Server に登録された node の情報を確認

Default Gateway 側の ip address が登録される

[workstation]$ knife node show node01
Node Name:   node01
Environment: lab
FQDN:        node01
IP:          192.168.0.10
Run List:
Roles:
Recipes:
Platform:    centos 7.0
Tags:

Workstation から ssh 出来ない

[workstation]$ knife ssh 'name:node01' hostname -x root
could not access

回避策

  1. knife ssh で attribute を指定する
  2. node の ip address を変更する
  3. custom ohai plugin を使う

1. knife ssh で attribute を指定する

Default の ipaddress ではなく、

[node]# ohai | grep ipaddress
  "ipaddress": "192.168.0.10",

別の ip address を指定したい。

[workstation]$ knife ssh 'name:node01' hostname -x root -a <ATTRIBUTE>

例えば、この attribute を指定したい、

  • chef-apply
[node]# chef-apply -e 'puts node[:network][:interfaces][:eth1][:routes][0][:src]'
10.10.0.10
  • chef-shell
[node]# chef-shell -z
chef (12.5.1)> attributes_mode
chef:attributes (12.5.1)>
chef:attributes > node[:network][:interfaces][:eth1][:routes][0][:src]
 => "10.10.0.10"

しかし、knife ssh の attribute に指定出来ない。たぶん指定方法が間違っている。

[workstation]$ knife ssh 'name:node01' hostname -x root -a network.interfaces.eth1.routes.[0].src
ERROR: TypeError: no implicit conversion of String into Integer

[workstation]$ knife ssh 'name:node01' hostname -x root -a network.interfaces.eth1.routes.0.src
ERROR: TypeError: no implicit conversion of String into Integer

諦めて No2 へ。。。

2. node の ip address を変更する

Download node json file

[workstation]$ knife download nodes/node01.json
Created nodes/node01.json

json 修正

  • ipaddress を変更
[workstation]$ vi nodes/node01.json
  • Workstation と Chef Server を比較
[workstation]$ knife diff nodes/node01.json
diff --knife nodes/node01.json nodes/node01.json
--- nodes/node01.json  yyyy-mm-dd hh:mm:ss.000000000 +0900
+++ nodes/node01.json  yyyy-mm-dd hh:mm:ss.000000000 +0900
@@ -2254,7 +2254,7 @@
         }
       }
     },
-    "ipaddress": "192.168.0.10",
+    "ipaddress": "10.10.0.10",
     "macaddress": "00:00:00:00:00:00",
     "ip6address": "0000::0000:0000:0000:0000",
     "cpu": {

Upload node json file

[workstation]$ knife upload nodes/node01.json

Chef server の登録状況を確認

[workstation]$ knife node show node01
Node Name:   node01
Environment: lab
FQDN:        node01
IP:          10.10.0.10
Run List:
Roles:
Recipes:
Platform:    centos 7.0
Tags:

Ssh test

[workstation]$ knife ssh 'name:node01' hostname -x root
node01 node01

3. custom ohai plugin を使う

https://docs.chef.io/ohai_custom.html

bootstrap 時に default gateway 以外の ip address を chef server に登録するようにする。

Environment

[chef server]# rpm -q chef-server-core
chef-server-core-12.1.2-1.el7.x86_64

[workstation]]# knife --version
Chef: 12.3.0

[node]# chef-client --version
Chef: 12.5.1
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1