{"id":7137,"date":"2021-12-17T13:21:32","date_gmt":"2021-12-17T04:21:32","guid":{"rendered":"https:\/\/learningbox.co.jp\/?p=7137"},"modified":"2021-12-17T13:21:32","modified_gmt":"2021-12-17T04:21:32","slug":"blog_serverspec","status":"publish","type":"post","link":"https:\/\/learningbox.co.jp\/en\/2021\/12\/17\/blog_serverspec\/","title":{"rendered":"Recommendations for implementing test automation Serverspec"},"content":{"rendered":"<p>\u9f8d\u91ce\u60c5\u5831\u30b7\u30b9\u30c6\u30e0\u6771\u4eac\u30c1\u30fc\u30e0\u3067\u3059\ud83d\udcbb\uff01<br \/>\n\u7a81\u7136\u3067\u3059\u304c\u3001\u30b5\u30fc\u30d0\u69cb\u7bc9\u6642\u306e\u69cb\u6210\u78ba\u8a8d\u3092\u3059\u308b\u969b\u306e\u78ba\u8a8d\u65b9\u6cd5\u306f\u3069\u306e\u3088\u3046\u306b\u3055\u308c\u3066\u307e\u3059\u304b\uff1f<br \/>\n\u9f8d\u91ce\u30b7\u30b9\u30c6\u30e0\u3067\u306f[Serverspec]\u3068\u3044\u3046ruby\u3092\u4f7f\u7528\u3057\u305f\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u3001\u30b5\u30fc\u30d0\u6bce\u306b\u69cb\u6210\u306e\u30c6\u30b9\u30c8\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u30b3\u30de\u30f3\u30c9\u3067\u306e\u51fa\u529b\u306e\u6bd4\u8f03\u3067\u3042\u3063\u305f\u308a\u3001\u5fdc\u7528\u3059\u308c\u3070\u3001\u3069\u306e\u30eb\u30fc\u30eb\u3067\u78ba\u8a8d\u3092\u884c\u3046\u304b\u8a2d\u5b9a\u3082\u53ef\u80fd\u306a\u305f\u3081\u6c4e\u7528\u6027\u3082\u9ad8\u304f\u5c0e\u5165\u3092\u9032\u3081\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u304a\u5ba2\u69d8\u74b0\u5883\u306e\u898f\u6a21\u306b\u3088\u308aconfig\u306e\u5024\u3092\u5909\u3048\u3066\u3044\u305f\u308a\u3001\u8d77\u52d5\u3057\u3066\u3044\u308b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3084\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u7570\u306a\u3063\u3066\u3044\u308b\u306a\u3069\u3001\u53f0\u6570\u304c\u5897\u3048\u3066\u304f\u308b\u3068\u624b\u4f5c\u696d\u3067\u306e\u78ba\u8a8d\u306b\u306f\u3001\u591a\u304f\u306e\u6642\u9593\u3092\u4f7f\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>Serverspec\u3067\u306f\u3001config\u306e\u6bd4\u8f03\u3084\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3084\u8d77\u52d5\u72b6\u6cc1\u3092\u7c21\u5358\u306b\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<br \/>\n\u30c6\u30b9\u30c8\u5bfe\u8c61\u304c\u3042\u308b\u7a0b\u5ea6\u30d1\u30bf\u30fc\u30f3\u5316\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u30c6\u30b9\u30c8\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u3044\u56de\u3059\u3053\u3068\u3067\u3001\u8907\u6570\u53f0\u306e\u78ba\u8a8d\u306e\u6642\u9593\u77ed\u7e2e\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306fserverspec\u3092\u307e\u3060\u77e5\u3089\u306a\u3044\u65b9\u5411\u3051\u306b\u3001\u3069\u306e\u3088\u3046\u306a\u30c4\u30fc\u30eb\u306a\u306e\u304b\u3054\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3059\u3002<\/p>\n<p class=\"mokujimidasi\">\n\u76ee\u6b21\u306f\u3053\u3061\u3089\n<\/p>\n<ol class=\"mokuji\">\n<li>\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308bOS<\/li>\n<li>\u78ba\u8a8d\u3067\u304d\u308b\u9805\u76ee<\/li>\n<li>\u5c0e\u5165\u65b9\u6cd5<\/li>\n<li>\u307e\u3068\u3081<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308bOS<\/h2>\n<p>\u30b5\u30fc\u30d0\u3068\u4e00\u8a00\u3067\u8a00\u3063\u3066\u3082\u3001\u73fe\u5728\u69d8\u3005\u306aOS\u304c\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u5b9f\u969b\u306b\u5229\u7528\u53ef\u80fd\u306aOS\u306f\u3001\u4e0b\u8a18\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p class=\"well\">\n* AIX<br \/>\n* Arch Linux<br \/>\n* Darwin(Mac OS X)<br \/>\n* Debian<br \/>\n* Fedora\/Red Hat\/CentOS<br \/>\n* FreeBSD<br \/>\n* Gentoo Linux<br \/>\n* NixOS<br \/>\n* OpenBSD<br \/>\n* openSUSE<br \/>\n* Plamo Linux<br \/>\n* SmartOS<br \/>\n* Solaris<br \/>\n* SUSE<br \/>\n* Ubuntu<br \/>\n* Windows\n<\/p>\n<p>\u4e00\u822c\u7684\u306b\u3088\u304f\u4f7f\u7528\u3055\u308c\u308b\u3001RedHat\u3084Ubuntu\u306a\u3069\u306eLinuxOS\u3084Windows\u3082\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001<br \/>\n\u3055\u307e\u3056\u307e\u306aOS\u3067\u5229\u7528\u3067\u304d\u307e\u3059\u3002<br \/>\n&nbsp;<\/p>\n<h2>\u78ba\u8a8d\u3067\u304d\u308b\u9805\u76ee<\/h2>\n<p><a href=\"https:\/\/serverspec.org\/resource_types.html\">serverspec\u306e\u516c\u5f0f<\/a>\u304b\u3089\u30c6\u30b9\u30c8\u3067\u304d\u308b\u9805\u76ee\u306e\u4e00\u89a7\u304c\u898b\u3089\u308c\u307e\u3059\u3002<br \/>\n\u69d8\u3005\u306a\u78ba\u8a8d\u3092\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u304c\u3001\u4eca\u56de\u30c6\u30b9\u30c8\u3067\u78ba\u8a8d\u3057\u305f\u9805\u76ee\u3092\u3044\u304f\u3064\u304b\u8a18\u8f09\u3044\u305f\u3057\u307e\u3059\u3002<\/p>\n<h3>file<\/h3>\n<p class=\"well\">\n-be_file \u30d5\u30a1\u30a4\u30eb\u306e\u6709\u7121\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b<br \/>\n-be_owned_by \u30d5\u30a1\u30a4\u30eb\u306e\u6240\u6709\u8005\u6a29\u9650\u306e\u78ba\u8a8d<br \/>\n-be_grouped_into \u30d5\u30a1\u30a4\u30eb\u306e\u30b0\u30eb\u30fc\u30d7\u306e\u78ba\u8a8d<br \/>\n-be_mode \u30d5\u30a1\u30a4\u30eb\u306e\u30e2\u30fc\u30c9\u78ba\u8a8d<br \/>\n-content \u30d5\u30a1\u30a4\u30eb\u5185\u306b\u6307\u5b9a\u306e\u8a18\u8ff0\u304c\u3042\u308b\u304b\u78ba\u8a8d\n<\/p>\n<h3>service<\/h3>\n<p class=\"well\">\n-be_enabled,be_running \u30b5\u30fc\u30d3\u30b9\u304c\u8d77\u52d5\u3057\u3066\u3044\u308b\u304b\u3001\u81ea\u52d5\u8d77\u52d5\u306b\u306a\u3063\u3066\u3044\u308b\u304b<br \/>\n-be_listening \u3057\u305f\u3044\u3057\u305f\u30dd\u30fc\u30c8\u304cListening\u72b6\u614b\u3068\u306a\u3063\u3066\u3044\u308b\u304b\n<\/p>\n<h3>package<\/h3>\n<p class=\"well\">\n-be_installed \u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d<br \/>\n-be_installed.with_version \u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\n<\/p>\n<h3>cron<\/h3>\n<p class=\"well\">\n-have_entry \u5bfe\u8c61\u306ecron\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u304b<\/p>\n<p>\u307e\u305f\u3001\u30b3\u30de\u30f3\u30c9\u306e\u8fd4\u308a\u5024\u3068\u6307\u5b9a\u3057\u305f\u5024\u3068\u306e\u30de\u30c3\u30c1\u3092\u78ba\u8a8d\u3059\u308b\u4e8b\u304c\u3067\u304d\u308b\u305f\u3081\u3001<br \/>\n\u30b3\u30de\u30f3\u30c9\u3067\u306e\u78ba\u8a8d\u65b9\u6cd5\u304b\u3089\u8272\u3005\u306a\u5fdc\u7528\u304c\u53ef\u80fd\u3067\u3059\u3002\n<\/p>\n<h3>\u4f8b<\/h3>\n<div class=\"wp-title\">#timestamp\u306e\u78ba\u8a8d<\/div>\n<div class=\"wp-block\">\n<pre>\r\n<code>\r\ndescribe command(\"date\") do\r\nits(:stdout) { should match \/JST\/ }\r\nend\r\n<\/code>\r\n<\/pre>\n<\/div>\n<div class=\"wp-title\">#swap\u30d5\u30a1\u30a4\u30eb\u306e\u78ba\u8a8d<\/div>\n<div class=\"wp-block\">\n<pre>\r\n<code>\r\ndescribe command(\"free\") do\r\nits(:stdout) { should match \/Swap:\/ }\r\nend\r\n<\/code>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>\u5c0e\u5165\u65b9\u6cd5<\/h2>\n<p>serverspec\u306e\u521d\u56de\u306e\u5c0e\u5165\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3054\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3059\u3002<br \/>\n\u203bruby\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u74b0\u5883\u3067\u5c0e\u5165\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>-ruby\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<div class=\"wp-block\">\n<pre>\r\n<code>\r\n$ bundle\r\n$ gem install serverspec\r\n<\/code>\r\n<\/pre>\n<\/div>\n<h3>Serverspec\u521d\u671f\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h3>\n<p>\u203bUnix\u7cfb\u304b\u3064SSH\u51fa\u6765\u308b\u74b0\u5883\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"well\">\n<code>$ serverspec-init<br \/>\nSelect OS type:<\/code><\/p>\n<p>1) UN*X<br \/>\n2) Windows<\/p>\n<p>Select number: 1<\/p>\n<p>Select a backend type:<\/p>\n<p>1) SSH<br \/>\n2) Exec (local)<\/p>\n<p>Select number: 1<\/p>\n<p>Vagrant instance y\/n: n<br \/>\nInput target host name: <a href=\"http:\/\/www.example.jp\" rel=\"nofollow\">http:\/\/www.example.jp<\/a><br \/>\n+ spec\/<br \/>\n+ spec\/www.example.jp\/<br \/>\n+ spec\/www.example.jp\/sample_spec.rb<br \/>\n+ spec\/spec_helper.rb<br \/>\n+ Rakefile<br \/>\n+ .rspec\n<\/p><\/div>\n<p>\u4e0b\u8a18\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30b5\u30f3\u30d7\u30eb\u306e\u30c6\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001<br \/>\n\u30b5\u30f3\u30d7\u30eb\u306e\u30c6\u30b9\u30c8\u5185\u5bb9\u306f\u3001<br \/>\nApache\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3001\u8d77\u52d5\u3001\u81ea\u52d5\u8d77\u52d5\u300180\u756a\u30dd\u30fc\u30c8\u304c\u30ea\u30c3\u30b9\u30f3\u3055\u308c\u3066\u3044\u308b\u304b<br \/>\n\u3068\u3044\u3063\u305f\u5185\u5bb9\u306b\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u4e0b\u8a18\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<br \/>\n<border-bottom>spec\/www.example.jp\/sample_spec.rb<\/border-bottom><\/p>\n<h3>\u5b9f\u969b\u306b\u30b5\u30fc\u30d0\u306b\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5<\/h3>\n<div class=\"wp-block\">\n<pre>\r\n<code>\r\n% rake spec\r\n<\/code>\r\n<\/pre>\n<\/div>\n<p>\u521d\u671f\u306e\u30b5\u30f3\u30d7\u30eb\u30d5\u30a1\u30a4\u30eb\u3067\u306f\u3001Apache\u3092\u4f7f\u3063\u305fweb\u30b5\u30fc\u30d0\u7528\u306e\u30c6\u30b9\u30c8\u3068\u306a\u3063\u3066\u304a\u308a\u3001<br \/>\nApache\u3092\u5229\u7528\u3057\u3066\u3044\u306a\u3044\u30b5\u30fc\u30d0\u306e\u30c6\u30b9\u30c8\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u3002<br \/>\n\u516c\u5f0f\u3092\u53c2\u7167\u306b\u30b5\u30fc\u30d0\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u306b<br \/>\nsample_spec.rb\u3092\u66f8\u304d\u63db\u3048\u308b\u7b49\u306e\u5bfe\u5fdc\u3092\u3057\u3066\u30c6\u30b9\u30c8\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n&nbsp;<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u4eca\u56de\u306e\u7d39\u4ecb\u3067\u306fsample\u3092\u4f7f\u3063\u305f\u7c21\u5358\u306a\u30c6\u30b9\u30c8\u3092\u884c\u3063\u3066\u307f\u307e\u3057\u305f\u304c\u3001<br \/>\n\u30b5\u30fc\u30d0\u5358\u4f4d\u3067\u8a2d\u5b9a\u3092\u5206\u3051\u305f\u308a\u3001\u7d39\u4ecb\u3067\u304d\u306a\u304b\u3063\u305f\u69d8\u3005\u306a\u30c6\u30b9\u30c8\u3082\u3042\u308a\u307e\u3059\u3002<br \/>\n\u8a66\u3057\u306b\u89e6\u3063\u3066\u307f\u3066\u3054\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u3001\u3054\u81ea\u8eab\u306e\u74b0\u5883\u3067\u5229\u7528\u3067\u304d\u308b\u304b\u8272\u3005\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u3044\u308d\u3093\u306a\u65b9\u304c\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5fdc\u7528\u65b9\u6cd5\u306f\u691c\u7d22\u3059\u308c\u3070\u3067\u3066\u304d\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001\u6a5f\u4f1a\u304c\u3042\u308c\u3070\u5fdc\u7528\u7de8\u3082\u6295\u7a3f\u3055\u305b\u3066\u3044\u305f\u3060\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u9f8d\u91ce\u60c5\u5831\u30b7\u30b9\u30c6\u30e0\u6771\u4eac\u30c1\u30fc\u30e0\u3067\u3059\ud83d\udcbb\uff01 \u7a81\u7136\u3067\u3059\u304c\u3001\u30b5\u30fc\u30d0\u69cb\u7bc9\u6642\u306e\u69cb\u6210\u78ba\u8a8d\u3092\u3059\u308b\u969b\u306e\u78ba\u8a8d\u65b9\u6cd5\u306f\u3069\u306e\u3088\u3046\u306b\u3055\u308c\u3066\u307e\u3059 [&hellip;]","protected":false},"author":63,"featured_media":7392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"0","_wpcom_ai_launchpad_first_post":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[12,6,7],"tags":[],"class_list":["post-7137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-blog","category-7"],"acf":[],"jetpack_featured_media_url":"https:\/\/learningbox.co.jp\/wp-content\/uploads\/2021\/12\/\u30b9\u30b9\u30e101.jpg","jetpack_shortlink":"https:\/\/wp.me\/pgMrZ4-1R7","_links":{"self":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/7137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/comments?post=7137"}],"version-history":[{"count":59,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/7137\/revisions"}],"predecessor-version":[{"id":7394,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/posts\/7137\/revisions\/7394"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/media\/7392"}],"wp:attachment":[{"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/media?parent=7137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/categories?post=7137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learningbox.co.jp\/en\/wp-json\/wp\/v2\/tags?post=7137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}