Mysql
伺服器上 mysql 版本的 serverspec if 語句
有沒有辦法通過命令輸出檢查伺服器上安裝的軟體包?
describe command('mysql -e "select version();"') do if its(:stdout) { should =~ /5.6.27-76.0-log/ } describe package('MySQL-client') do it { should be_installed } else describe package('Percona-client') do it { should be_installed } end end
謝謝,
好吧,我想不出比這更好的方法了:
def mysql_version command('mysql -e "select version();"').stdout end def plain_mysql? mysql_version =~ /5.6.27-76.0-log/ end def mysql_package_name if plain_mysql? 'MySQL-client' else 'Percona-client' end end describe package(mysql_package_name) do it { should be_installed } end