从文档看来,使用 Serverspec 来验证是否安装了软件包应该非常简单,但是我遇到了一些有趣的问题vim
和ag
( the_silver_searcher
)。
我正在使用带有kitchen-vagrant
插件的 Test Kitchen,并且有两个平台:ubuntu-1404
和centos-72
. 我的所有规格都通过了 Ubuntu,其中两个不适合 Centos:vim
和ag
.
vim
处理此安装的 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
在登录时输入(退出状态1
)确实会产生该使用内容,上述内容也不起作用。我的最后一次尝试是:
describe file("/usr/local/bin/ag") do
it { should exist }
end
这行得通,但感觉超级hacky,好像没有必要。
有人在这里推荐吗?这些包有什么我遗漏/做错的吗?我最初认为ag
问题只是因为它是从源安装而不是包管理器,但是使用包管理vim
器安装并且仍然存在与ag
.