Ruby 从chef recipe中执行shell脚本
我必须根据从ubuntu节点得到的结果,从recipe中执行一个脚本。我必须运行代理的版本,并在此基础上执行脚本。下面是我正在运行的配方中的条件Ruby 从chef recipe中执行shell脚本,ruby,shell,chef-infra,chef-recipe,Ruby,Shell,Chef Infra,Chef Recipe,我必须根据从ubuntu节点得到的结果,从recipe中执行一个脚本。我必须运行代理的版本,并在此基础上执行脚本。下面是我正在运行的配方中的条件 notifies :run, 'bash[uninstall CloudPassage]', :immediate only_if { Mixlib::ShellOut.new("dpkg -s cphalo | grep Version | awk '{print $2}'" -lt "3.9.5").run_command.success? }
notifies :run, 'bash[uninstall CloudPassage]', :immediate
only_if { Mixlib::ShellOut.new("dpkg -s cphalo | grep Version | awk '{print $2}'" -lt "3.9.5").run_command.success? }
但它给出了一个语法。有人能帮我从ubuntu节点获取版本号的语法吗
语法错误:
此脚本检查
cphalo
版本是否小于(-lt
)3.9.5
- 使用
读取cphalo
获取行:Version
"dpkg -s cphalo | grep Version"
- 然后将其输送到
并打印第二个字段(awk
)$2
- 由于
-lt
或者,如果需要方括号:">result<" -lt "3.9.5"
" [ $(dpkg -s cphalo | grep Version | awk '{print $2}') -lt 3.9.5 ] "
正确的er书写方式:only_if { Gem::Requirement.create('< 3.9.5').satisfied_by?(Gem::Version.create(shell_out!('dpkg -s cphalo').stdout[/^Version: (.*)$/, 1])) }
仅当{Gem::Requirement.create('<3.9.5')。满足?(Gem::Version.create(shell_out!('dpkg-s cphalo')。stdout[/^Version:(.*)$/,1]))
或者类似的东西。我已经编写了条件,但条件给出了来自chef recipe的语法错误。已上载烹饪书,但chef客户端在节点中出现故障,我的only_if block中是否有错误?您尝试过这两种解决方案吗
如果[y.x-lt a.b]
小于y.x
,则会显示a.b
。如果另一条消息失败,可能吗?在服务器上运行shell命令时会得到什么?好的,我对cookbook不太了解<代码>[3.9.5-lt 3.9.5]适用于标准外壳。至少修复了语法错误。0
" $(dpkg -s cphalo | grep Version | awk '{print $2}') -lt 3.9.5 "
" [ $(dpkg -s cphalo | grep Version | awk '{print $2}') -lt 3.9.5 ] "
only_if { Gem::Requirement.create('< 3.9.5').satisfied_by?(Gem::Version.create(shell_out!('dpkg -s cphalo').stdout[/^Version: (.*)$/, 1])) }