获取 sh:pvdisplay:升级到 Chef 客户端 16 后找不到命令
Getting sh: pvdisplay: command not found after upgrading to chef client 16
最近我们将 chef-client 从 12.8.1 升级到 16.1.16..
将 chef-client 从 12.8.1 升级到 16.1.16 后,出现以下错误。
为了测试,我将 chef-client 恢复到 12.8.1 并且部署在 12.8.1 上工作正常。
是否有任何我缺少的代码重构需要升级到 Chef 16.1.16 版本。
20:14:26 * execute[pvcreate] action run[2020-09-09T10:44:26-04:00] INFO: Processing execute[pvcreate] action run (ReportTomcat::default line 153)
20:14:26 [2020-09-09T10:44:26-04:00] INFO: Processing execute[Guard resource] action run (dynamically defined)
20:14:26 sh: pvdisplay: command not found
20:14:26
20:14:26 [execute] Can't initialize physical volume "/dev/sdc" of volume group "CSPD1VFPR02-ReportTomcat" without -ff
20:14:26 /dev/sdc: physical volume not initialized.
20:14:26
20:14:26 ================================================================================
20:14:26 [31mError executing action `run` on resource 'execute[pvcreate]'[0m
20:14:26 ================================================================================
20:14:26
20:14:26 Mixlib::ShellOut::ShellCommandFailed
20:14:26 ------------------------------------
20:14:26 Expected process to exit with [0], but received '5'
20:14:26 ---- Begin output of /sbin/pvcreate /dev/sdc ----
20:14:26 STDOUT:
20:14:26 STDERR: Can't initialize physical volume "/dev/sdc" of volume group "CSPD1VFPR02-ReportTomcat" without -ff
20:14:26 /dev/sdc: physical volume not initialized.
20:14:26 ---- End output of /sbin/pvcreate /dev/sdc ----
20:14:26 Ran /sbin/pvcreate /dev/sdc returned 5
20:14:26
20:14:26 Resource Declaration:
20:14:26 ---------------------
20:14:26 # In /etc/chef/local-mode-cache/cache/cookbooks/ReportTomcat/recipes/default.rb
20:14:26
20:14:26 153: execute "pvcreate" do
20:14:26 154: command "/sbin/pvcreate #{ node['il']['ReportTomcat']['pvcreate']['drive']}"
20:14:26 155: not_if "pvdisplay | grep #{ node['il']['ReportTomcat']['pvcreate']['drive']}"
20:14:26 156: end
20:14:26 157:
20:14:26
20:14:26 Compiled Resource:
20:14:26 ------------------
20:14:26 # Declared in /etc/chef/local-mode-cache/cache/cookbooks/ReportTomcat/recipes/default.rb:153:in `from_file'
20:14:26
20:14:26 execute("pvcreate") do
20:14:26 action [:run]
20:14:26 default_guard_interpreter :execute
20:14:26 command "/sbin/pvcreate /dev/sdc"
20:14:26 backup 5
20:14:26 declared_type :execute
20:14:26 cookbook_name "ReportTomcat"
20:14:26 recipe_name "default"
20:14:26 domain nil
20:14:26 user nil
20:14:26 not_if "pvdisplay | grep /dev/sdc"
20:14:26 end
在其他部署中,出现以下错误。
20:43:27 [execute] dzdo: sysctl: command not found
20:43:27 dzdo: sysctl: command not found
20:43:27
20:43:27 ================================================================================
20:43:27 [31mError executing action `run` on resource 'bash[extract_module]'[0m
20:43:27 ================================================================================
20:43:27
20:43:27 Mixlib::ShellOut::ShellCommandFailed
20:43:27 ------------------------------------
20:43:27 Expected process to exit with [0], but received '1'
20:43:27 ---- Begin output of "bash" "/tmp/chef-script20200909-22973-7ommnx" ----
20:43:27 STDOUT:
20:43:27 STDERR: dzdo: sysctl: command not found
20:43:27 dzdo: sysctl: command not found
20:43:27 ---- End output of "bash" "/tmp/chef-script20200909-22973-7ommnx" ----
20:43:27 Ran "bash" "/tmp/chef-script20200909-22973-7ommnx" returned 1
20:43:27
20:43:27 Resource Declaration:
20:43:27 ---------------------
20:43:27 # In /etc/chef/local-mode-cache/cache/cookbooks/il-content-middleware-service/recipes/contentmiddleware_service.rb
20:43:27
20:43:27 59: bash 'extract_module' do
20:43:27 60: code <<-EOH
20:43:27 61: sudo sysctl -w net.core.somaxconn=1024
20:43:27 62: sudo sysctl -w net.ipv4.tcp_max_syn_backlog=4096
20:43:27 63: EOH
20:43:27 64: end
20:43:27 65:
出现此问题是因为在 Chef 14.2 中向 execute 资源添加了一个新的 属性。
default_env
Ruby Type: true, false | Default Value: false
When true this enables ENV magic to add path_sanity to the PATH and force the locale to English+UTF-8 for parsing output
New in Chef Client 14.2
这就是为什么 /sbin/pvcreate
是 运行(尽管它失败了),而不是 pvdisplay
。
在 client.rb 配置中对此有进一步的解释。
enforce_path_sanity
Turn on path sanity in resources that shellout so that expected paths like /sbin or /bin are added to the PATH. Disabled by default.
您可以用不同的方式修复它:
在您的 execute/bash 资源中为命令使用绝对路径。示例:
not_if "/sbin/pvdisplay | grep #{node['il']['ReportTomcat']['pvcreate']['drive']}"
sudo /sbin/sysctl -w net.core.somaxconn=1024
将 default_env true
添加到您的执行资源。示例:
execute 'pvcreate' do
command "pvcreate #{node['il']['ReportTomcat']['pvcreate']['drive']}"
default_env true
not_if "pvdisplay | grep #{node['il']['ReportTomcat']['pvcreate']['drive']}"
end
在client.rb
中启用enforce_path_sanity
,这将对ShellOut
的所有Chef资源生效。示例:
enforce_path_sanity true
enforce_path_sanity
替换为 enforce_default_paths
。 github 厨师有一个未解决的问题。
最近我们将 chef-client 从 12.8.1 升级到 16.1.16.. 将 chef-client 从 12.8.1 升级到 16.1.16 后,出现以下错误。 为了测试,我将 chef-client 恢复到 12.8.1 并且部署在 12.8.1 上工作正常。 是否有任何我缺少的代码重构需要升级到 Chef 16.1.16 版本。
20:14:26 * execute[pvcreate] action run[2020-09-09T10:44:26-04:00] INFO: Processing execute[pvcreate] action run (ReportTomcat::default line 153)
20:14:26 [2020-09-09T10:44:26-04:00] INFO: Processing execute[Guard resource] action run (dynamically defined)
20:14:26 sh: pvdisplay: command not found
20:14:26
20:14:26 [execute] Can't initialize physical volume "/dev/sdc" of volume group "CSPD1VFPR02-ReportTomcat" without -ff
20:14:26 /dev/sdc: physical volume not initialized.
20:14:26
20:14:26 ================================================================================
20:14:26 [31mError executing action `run` on resource 'execute[pvcreate]'[0m
20:14:26 ================================================================================
20:14:26
20:14:26 Mixlib::ShellOut::ShellCommandFailed
20:14:26 ------------------------------------
20:14:26 Expected process to exit with [0], but received '5'
20:14:26 ---- Begin output of /sbin/pvcreate /dev/sdc ----
20:14:26 STDOUT:
20:14:26 STDERR: Can't initialize physical volume "/dev/sdc" of volume group "CSPD1VFPR02-ReportTomcat" without -ff
20:14:26 /dev/sdc: physical volume not initialized.
20:14:26 ---- End output of /sbin/pvcreate /dev/sdc ----
20:14:26 Ran /sbin/pvcreate /dev/sdc returned 5
20:14:26
20:14:26 Resource Declaration:
20:14:26 ---------------------
20:14:26 # In /etc/chef/local-mode-cache/cache/cookbooks/ReportTomcat/recipes/default.rb
20:14:26
20:14:26 153: execute "pvcreate" do
20:14:26 154: command "/sbin/pvcreate #{ node['il']['ReportTomcat']['pvcreate']['drive']}"
20:14:26 155: not_if "pvdisplay | grep #{ node['il']['ReportTomcat']['pvcreate']['drive']}"
20:14:26 156: end
20:14:26 157:
20:14:26
20:14:26 Compiled Resource:
20:14:26 ------------------
20:14:26 # Declared in /etc/chef/local-mode-cache/cache/cookbooks/ReportTomcat/recipes/default.rb:153:in `from_file'
20:14:26
20:14:26 execute("pvcreate") do
20:14:26 action [:run]
20:14:26 default_guard_interpreter :execute
20:14:26 command "/sbin/pvcreate /dev/sdc"
20:14:26 backup 5
20:14:26 declared_type :execute
20:14:26 cookbook_name "ReportTomcat"
20:14:26 recipe_name "default"
20:14:26 domain nil
20:14:26 user nil
20:14:26 not_if "pvdisplay | grep /dev/sdc"
20:14:26 end
在其他部署中,出现以下错误。
20:43:27 [execute] dzdo: sysctl: command not found
20:43:27 dzdo: sysctl: command not found
20:43:27
20:43:27 ================================================================================
20:43:27 [31mError executing action `run` on resource 'bash[extract_module]'[0m
20:43:27 ================================================================================
20:43:27
20:43:27 Mixlib::ShellOut::ShellCommandFailed
20:43:27 ------------------------------------
20:43:27 Expected process to exit with [0], but received '1'
20:43:27 ---- Begin output of "bash" "/tmp/chef-script20200909-22973-7ommnx" ----
20:43:27 STDOUT:
20:43:27 STDERR: dzdo: sysctl: command not found
20:43:27 dzdo: sysctl: command not found
20:43:27 ---- End output of "bash" "/tmp/chef-script20200909-22973-7ommnx" ----
20:43:27 Ran "bash" "/tmp/chef-script20200909-22973-7ommnx" returned 1
20:43:27
20:43:27 Resource Declaration:
20:43:27 ---------------------
20:43:27 # In /etc/chef/local-mode-cache/cache/cookbooks/il-content-middleware-service/recipes/contentmiddleware_service.rb
20:43:27
20:43:27 59: bash 'extract_module' do
20:43:27 60: code <<-EOH
20:43:27 61: sudo sysctl -w net.core.somaxconn=1024
20:43:27 62: sudo sysctl -w net.ipv4.tcp_max_syn_backlog=4096
20:43:27 63: EOH
20:43:27 64: end
20:43:27 65:
出现此问题是因为在 Chef 14.2 中向 execute 资源添加了一个新的 属性。
default_env
Ruby Type: true, false | Default Value: false
When true this enables ENV magic to add path_sanity to the PATH and force the locale to English+UTF-8 for parsing output
New in Chef Client 14.2
这就是为什么 /sbin/pvcreate
是 运行(尽管它失败了),而不是 pvdisplay
。
在 client.rb 配置中对此有进一步的解释。
enforce_path_sanity
Turn on path sanity in resources that shellout so that expected paths like /sbin or /bin are added to the PATH. Disabled by default.
您可以用不同的方式修复它:
在您的 execute/bash 资源中为命令使用绝对路径。示例:
not_if "/sbin/pvdisplay | grep #{node['il']['ReportTomcat']['pvcreate']['drive']}"
sudo /sbin/sysctl -w net.core.somaxconn=1024
将
default_env true
添加到您的执行资源。示例:execute 'pvcreate' do command "pvcreate #{node['il']['ReportTomcat']['pvcreate']['drive']}" default_env true not_if "pvdisplay | grep #{node['il']['ReportTomcat']['pvcreate']['drive']}" end
在
client.rb
中启用enforce_path_sanity
,这将对ShellOut
的所有Chef资源生效。示例:enforce_path_sanity true
enforce_path_sanity
替换为 enforce_default_paths
。 github 厨师有一个未解决的问题。