すぐに忘れるのでメモ。
chef
ohaiのplatform
に情報が入っています。
RHEL 6.9
$ ohai | grep platform
[2018-02-01T10:57:15+09:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
"platform": "redhat",
"platform_version": "6.9",
"platform_family": "rhel",
"xen-platform-pci"
CentOS 6.9
$ ohai | grep platform
[2018-02-01T01:58:08+00:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
"platform": "centos",
"platform_version": "6.9",
"platform_family": "rhel",
AmazonLinux 2017.03
$ ohai | grep platform
[2018-02-01T10:59:18+09:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
"platform": "amazon",
"platform_version": "2017.03",
"platform_family": "amazon",
Chefの判定まとめ
実際のOS | platform | platform_version | platform_family |
---|---|---|---|
RHEL6.9 | redhat | 6.9 | rhel |
CentOS6.9 | centos | 6.9 | rhel |
AmazonLinux | amazon | 2017.03 | amazon |
platform, platform_version, platform_familyを使用すればよい。
serverspec
host_inventoryの構造がよくわからなかったのですが、どうもOSに関するものは http://serverspec.org/host_inventory.html にある情報がすべてであり、
host_inventory['platform'] # => redhat
host_inventory['platform_version'] # => 6.5
の2種類が取れるようでした。 ちなみに、chefを使っていればserverspecはohaiの値も取れるので、
CentOS 6.9の場合
host_inventory['ohai']['platform'] // "centos"が返る
host_inventory['platform_version'] // "6.9"が返る
host_inventory['ohai']['platform_family'] // "rhel"が返る
host_inventory['ohai']['platform_version'] // "6.9"が返る
RHEL 6.9の場合
host_inventory['ohai']['platform'] // "redhat"が返る
host_inventory['platform_version'] // "6.9"が返る
host_inventory['ohai']['platform_family'] // "rhel"が返る
host_inventory['ohai']['platform_version'] // "6.9"が返る
とCentOSとRHELを同じく扱いたい場合などは、ohaiを組み合わせるのが良いようです。