Help us understand the problem. What is going on with this article?

Serverspec書き方

More than 1 year has passed since last update.

概要

Serverspecの書き方メモ。随時追加します。

関連記事

Serverspec環境構築手順

書式

service起動評価

describe service('nginx') do
  it { should be_enabled }
  it { should be_running }
end

fileの中身評価

describe file('/usr/local/nginx/conf/nginx.conf') do
  text = 'server_name 192.168.33.10;'
  # should match /server_name\ 192\.168\.33\.10;/
  its(:content) { should match /#{Regexp.escape(text)}/ }
  # should match "server_name 192.168.33.10;"
  its(:content) { should match text }
end

command実行結果評価

describe command('curl -L http://xxxx.com') do
  # should match /"status":201/
  its(:stdout) { should match /#{Regexp.escape('"status":200')}/ }
  # should match "\"status\":201"
  its(:stdout) { should match '"status":200' }
end

commandを叩くだけ(結果は評価しない)

spec/sample_spec.rb
require 'spec_helper'

stdout = Specinfra.backend.run_command('ls').stdout.strip
puts stdout

参考

serverspecのリソースタイプ・マッチャー

Esfahan
WEB系出身。現在はビッグデータの基盤構築、ETLなどがメイン。 / YouTubeで料理チャンネルやってます → https://www.youtube.com/channel/UCDnYBh2TtUAfQ0Z-tl0jTyw
https://www.youtube.com/channel/UCDnYBh2TtUAfQ0Z-tl0jTyw
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした