ドキュメントからは、Serverspec を使用してパッケージがインストールされていることを確認するのはかなり簡単なようですが、vim
and ag
( the_silver_searcher
) に関して興味深い問題がいくつかあります。
私はkitchen-vagrant
プラグインで Test Kitchen を使用しており、2 つのプラットフォームがあります:ubuntu-1404
とcentos-72
. 私の仕様はすべて Ubuntu に合格し、そのうちの 2 つは Centos に不合格です:vim
とag
.
ヴィム
このインストールを処理する Chef コードは非常に単純です。
package "vim"
そして、ここに仕様があります:
describe "Vim" do
describe package("vim") do
it { should be_installed }
end
end
繰り返しますが、非常に簡単です。ただし、Centos ビルドでは次のエラーで失敗します。
2) Vim Package "vim" should be installed
Failure/Error: it { should be_installed }
expected Package "vim" to be installed
/bin/sh -c rpm\ -q\ vim
package vim is not installed
それでも、サーバーにログインすると、間違いなくインストールされます。
▶ kitchen login all-centos-72
Last login: Sat Jul 2 17:53:30 2016 from 10.0.2.2
[vagrant@all-centos-72 ~]$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 10 2014 06:55:55)
[vagrant@all-centos-72 ~]$ which vim
/usr/bin/vim
[vagrant@all-centos-72 ~]$ sudo yum install -y vim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: distro.ibiblio.org
* extras: mirror.us.leaseweb.net
* updates: mirror.eboundhost.com
Package 2:vim-enhanced-7.4.160-1.el7.x86_64 already installed and latest version
Nothing to do
銀
ag
Centos ではソースからビルドする必要があるのに対し、Ubuntu ではapt-get
. レシピの関連部分は次のとおりです。
bash "install Development Tools" do
code "yum -y groupinstall \"Development Tools\""
end
package %w(pcre-devel xz-devel)
target_dir = File.join("/", "usr", "local", "the_silver_searcher")
git "clone the ag repo" do
repo "https://github.com/ggreer/the_silver_searcher/"
revision "master"
destination target_dir
end
bash "install ag" do
not_if system("hash ag")
cwd target_dir
code <<-EOF
./build.sh
make install
EOF
end
そして、ここに仕様があります:
describe "The Silver Searcher" do
if host_inventory["platform"] == "ubuntu"
describe package("silversearcher-ag") do
it { should be_installed }
end
else
describe package("the_silver_searcher") do
it { should be_installed }
end
end
end
Centos の失敗:
1) The Silver Searcher Package "the_silver_searcher" should be installed
Failure/Error: it { should be_installed }
expected Package "the_silver_searcher" to be installed
/bin/sh -c rpm\ -q\ the_silver_searcher
package the_silver_searcher is not installed
同様に、Centos VM にログインすると、以下を使用できますag
。
[vagrant@all-centos-72 ~]$ ag --version
ag version 0.32.0
[vagrant@all-centos-72 ~]$ which ag
/usr/local/bin/ag
これらのコマンドは、ユーザーに切り替えても機能しroot
ます。
Centos プラットフォーム用にさまざまな方法で仕様を記述して、システムをごまかそうとしました。
describe command("ag") do
its(:stderr) { should match /Usage: ag/ }
end
ag
ログイン時に入力すると ( exit status 1
)、その使用コンテンツが生成されますが、上記も機能しません。私の最後の試みは:
describe file("/usr/local/bin/ag") do
it { should exist }
end
これは機能しますが、非常にハッキーに感じられ、必要ではないようです。
ここでおすすめはありますか?これらのパッケージで不足している/間違っていることはありますか? 最初は、ag
問題はパッケージ マネージャーではなくソースからインストールされたためだと思っていましたvim
が、パッケージ マネージャーを使用してインストールされ、ag
.