serverspec if 语句用于服务器上的 mysql 版本

serverspec if 语句用于服务器上的 mysql 版本

有没有办法通过命令输出检查服务器上安装了哪些包?

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

谢谢,

答案1

好吧,我找不到比这更好的办法了:

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

相关内容