Serverspec ファイルに読み込み権限があるか確認するサンプル

環境
Serverspec
Ansible

操作例
1.ファイルの中身が指定の文字列にマッチするか確認する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
describe file('/etc/sysconfig/clock') do
its(:content) { should match /ZONE="Asia\/Tokyo"/ }
end
describe file('/etc/sysconfig/clock') do its(:content) { should match /ZONE="Asia\/Tokyo"/ } end
describe file('/etc/sysconfig/clock') do
  its(:content) { should match /ZONE="Asia\/Tokyo"/ }
end

2.ファイルに読み込み権限があるか確認する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
%w{
/var/log/httpd/access.log
/var/log/httpd/error.log
}.each do |logfile|
describe file(logfile) do
it { should be_readable.by_user('tent') }
end
end
%w{ /var/log/httpd/access.log /var/log/httpd/error.log }.each do |logfile| describe file(logfile) do it { should be_readable.by_user('tent') } end end
%w{
  /var/log/httpd/access.log
  /var/log/httpd/error.log
}.each do |logfile|
  describe file(logfile) do
    it { should be_readable.by_user('tent') }
  end
end

 

Ansible

Posted by arkgame